Skip to main content

Questions tagged [shell-builtin]

A shell builtin is a command called from a shell, that is executed directly in the shell itself.

Filter by
Sorted by
Tagged with
0 votes
1 answer
46 views

Can bash natively re-format a relative path to an absolute path, or not - being dependent on tool "realpath"?

UPDATE Once again, I can't post an answer to my question! Clicking the button just triggers an error message: "Unable to load popup - please try again". So, I have no other choice than to ...
futurewave's user avatar
1 vote
2 answers
121 views

How do I use a nonstandard file descriptor for reading a file into an array with mapfile?

mapfile -t -u 7 arr < textfile gives me bash: mapfile: 7: invalid file descriptor: Bad file descriptor Other, more verbose, methods of reading files line-by-line do allow for such descriptor, e.g. ...
John Smith's user avatar
1 vote
2 answers
232 views

How To Auto `command -p` In All My Script?

I want to execute all commands within my script with command -p e.g.: command -p pwd Because there may be some command that I will execute within the script whose name is being used by some other ...
rhuanpk's user avatar
  • 415
-1 votes
1 answer
106 views

Is the following `readonly` use POSIX-ly correct?

I defined the following as read-only: readonly root_command='sudo -s' later used in my script as in: exec $root_command My question is, maybe I am slow or something, but I do not fully understand ...
Vlastimil Burián's user avatar
1 vote
2 answers
80 views

How to avoid kickout from SSH when script fail

Please forgive my basic unix/linux scripting skill and poor English I am testing a script in the Linux VM, let's say it is work.sh. So I have to ssh to the VM ssh [email protected] with my ...
Dreamer's user avatar
  • 115
0 votes
0 answers
33 views

How to interpret different behavior of sleep and wait when they are interrupted

I'm trying to understand the subtleties between sleep and sleep & wait. If run the script test.sh #!/bin/bash sleep 10000 in one terminal and ps -aef --forest in another terminal, then I see ...
user1335014's user avatar
1 vote
1 answer
174 views

some_variable vs some-variable in zsh

Why is it that zsh seems to understand what to do with some_variable=1 command, but not some-variable=1 command? E.g.: $ fs_screen=1 mpv --fs-screen=${fs_screen} someFile.mp4 works fine but $ fs-...
Harv's user avatar
  • 2,174
0 votes
3 answers
264 views

arbitrary base conversion from base 10 using only builtins in bash

I'm trying to sort out a bash command to convert a number from base 10 to an arbitrary base, using a specified set of characters (for example, to base 26 using letters a-z, although that's not ...
Hate9's user avatar
  • 21
1 vote
0 answers
65 views

Why is `popd` popping the wrong directory?

Is this expected behavior from popd? >>> dirs -v 0 dirA 1 dirB >>> dirs +0 dirA >>> popd -n +0 dirA >>> dirs -v 0 dirA I would expect the last line to tell me that ...
Eric Auld's user avatar
  • 111
-1 votes
1 answer
76 views

Why do the [ -z ] and the [ -n ] flags both return true when used without an expression or when testing an unset variable? [duplicate]

From the man test pages: -n STRING the length of STRING is nonzero STRING equivalent to -n STRING -z STRING the length of STRING is zero Executing [ -n $foo ], [ -n ], [ -z $foo ], [ -z ], ...
NerdyDeeds's user avatar
0 votes
1 answer
100 views

Problem with bash builtin bind and escaping

I'm trying to add a history fuzzyfind hotkey to my bash shell. However, my intended command gets cut in the middle: [april@Capybara-2:~]$ cat ~/.bashrc bind "\"\C-r\": \"\$(...
AprilGrimoire's user avatar
32 votes
1 answer
3k views

How to get the cd shell-builtin to stop guessing?

For example: $ ls -aF ./ ../ bin/ $ cd tin # with a tee, not bee bin $ pwd /home/user/bin In other words, cd guesses that what I really meant was cd bin, and successfully (huh?) changes the current ...
Ana Nimbus's user avatar
2 votes
1 answer
245 views

Using set -e (errexit) with block of commands and executing another on fail of that block (SC2181)

I just found out about set -e as I was searching for an answer to "how to run many commands (without &&) and immediately stop on non-zero exit code of any of them?". The set -e was ...
Andrew15_5's user avatar
0 votes
1 answer
92 views

Why do some shell commands which are shell functions not always available?

I have noticed that using zsh the history command is not available when executed from Emacs via shell-command. history | grep runserver results in zsh:fc:1: no such event: 1. I also use the histdb ...
vfclists's user avatar
  • 7,619
1 vote
1 answer
108 views

Why does `print -c` fail, but piping to `column` succeed to print columns?

This works: #!/bin/zsh ### List apps ### arch="$(paru --query --quiet --explicit --unrequired)" repos=( $HOME/repos/./* ) npm=( $(npm list --global --parseable) ) box="${(l:20::─:)}&...
Pound Hash's user avatar
1 vote
2 answers
293 views

How can one modify the named directory hash table by "creating appropriate shell parameters"?

I'm used to add entrys to zshs named driectory hash table, by using hash -d <name>=<value>. Recently, I read the zshbuiltins(1) man page, where I found the following (description of the ...
ixolius's user avatar
  • 157
0 votes
2 answers
743 views

Cannot Display Bash Functions within FZF Preview Window

How do I get the FZF Preview Window to Display Functions from my Current Bash Environment? I want to list my custom bash functions using FZF, and view the code of a selected function in the FZF ...
user2514157's user avatar
3 votes
2 answers
166 views

Exporting zsh history separated by ‘\0’ characters instead of ‘\n’

I want to access zsh history with entries separated out by \0 instead of \n. The built-in parser can clearly handle multiline entries, because fc 123 brings up an editor with newlines preserved. ...
gcv's user avatar
  • 133
0 votes
1 answer
569 views

/usr/bin/type vs. bash's built-in type command

I was reading an article on various Linux commands that can show location of programs in the search path, including which, type, and whereis. The article says that type is a built-in bash command, and ...
dfsbbl's user avatar
  • 1
2 votes
1 answer
568 views

About Precommand Modifiers in zsh

Background While the zsh documentation (ch 6.2) provides a description for what precommand modifiers can do, it fails to provide examples for each type: -, builtin, command, exec, nocorrect, and ...
Майкл Шодеке's user avatar
2 votes
2 answers
342 views

What is the zsh equivalent of "pushd -n" in bash?

I want to push a directory onto the directory stack in order to refer to it using "tilde shorthand" (eg. ~1 refers to the second entry in the directory list), but I don't want to actually ...
chb's user avatar
  • 659
1 vote
1 answer
1k views

Is there a way to print the commands that the shell builtin `source` is calling when sourcing a script? [duplicate]

sh, bash, etc. have a -x flag that will show you each command that is executing in a script. This is handy for debugging. $ sh -x my_script.sh + case $SOMETHING_DIR in + unset ...
marathon's user avatar
  • 953
-4 votes
1 answer
4k views

How to resolve this error for 'help' command not found in Kali Linux? [closed]

I know that help is a shell built-in internal command used to find about built in commands such as cd. But it is not working in my Kali Linux terminal in VirtualBox. It is showing the following error: ...
UN90's user avatar
  • 1
6 votes
3 answers
1k views

checkbashisms: what's wrong with `type'?

#!/bin/sh foo() { echo "in foo" } type foo checkbashisms.pl obviously does not like type, why? $ checkbashisms.pl foo.sh possible bashism in foo.sh line 7(type): type foo Is it not ...
pevik's user avatar
  • 1,525
4 votes
2 answers
948 views

Bash's read builtin errors on a string-based timeout option specification but not an array-based one. Why?

In reading through the source to fff to learn more about Bash programming, I saw a timeout option passed to read as an array here: read "${read_flags[@]}" -srn 1 && key "$REPLY&...
qmacro's user avatar
  • 143
1 vote
1 answer
903 views

zsh: Halt when command not found

I want to stop the zsh script running when it encounters a command not found error. I know of command_not_found_handler, but this function only allows me to print a message, not halt the parent shell. ...
HappyFace's user avatar
  • 1,620
6 votes
1 answer
518 views

Difference between command `command` vs command `builtin` in Shell Scripting

I understand the command command is specified in the latest POSIX standard and builtin is not. I also realize that both commands are regular builtins (i.e. they can be overwritten by user-defined ...
adam.hendry's user avatar
2 votes
1 answer
3k views

How to detect EOF on a BASH script's stdin?

I have a bash function inside a script that needs to read data from stdin in fixed size blocks and send those, one at a time, to external programs for further processing. The function itself should ...
basher's user avatar
  • 21
5 votes
1 answer
1k views

Are there any caveats in using shopt -s autocd?

I have recently discovered the feature shopt -s autocd: autocd If set, a command name that is the name of a directory is executed as if it were the ...
mgarort's user avatar
  • 465
0 votes
1 answer
157 views

What is the intended purpose of the () syntax in a bash function?

I am freshening up my bash skills. I use the term skills very loosely; I've been outta the game a long time. So, as a way to brush up, I decided to code something utilizing bash/zenity/yad. I read man ...
endorpheus's user avatar
7 votes
5 answers
2k views

IFS=',' /usr/bin/read vs IFS=',' read

Context $ bash --version GNU bash, version 4.4.19(1)-release (x86_64-redhat-linux-gnu) Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/...
WMC's user avatar
  • 171
1 vote
1 answer
1k views

replace space with underscore in expect script

#!/usr/bin/expect -f set cmd "abc def ghi lkj" set log [ expr echo ${cmd// /_} ] I would like to log variable as ghi_lkj first I wast trying to replace all spaces with underscores and then ...
bhr's user avatar
  • 103
8 votes
1 answer
2k views

Is there a command to get builtin commands on zsh?

Is there a command to get builtin commands on zsh? For example, it is possible to get all builtin commands with the compgen -b command in the bash shell.
testter's user avatar
  • 1,470
33 votes
5 answers
8k views

Can I make cd be local to a function?

Is it possible to make a function like function doStuffAt { cd $1 # do stuff } but make it so invoking that function doesn't actually change my pwd, it just changes it for duration of the ...
Mason's user avatar
  • 489
8 votes
2 answers
2k views

Bash autocomplete: List files and directories from other directory

I wrote a script called prpsls which creates or edits files inside the directory ~/proposals. Now I'm writing the autocomplete script for it, and I'm trying to set it up in a way that, after I hit Tab,...
Ivan Gonzalez's user avatar
4 votes
1 answer
564 views

zsh: Read from stdin until a string delimiter

I want to read from stdin until a string delimiter MARKER=$'\0'"BRISH_MARKER" is encountered. I tried: ❯ unset br ; print -rn -- hi${MARKER}world | { IFS= read -d "$MARKER" -r ...
HappyFace's user avatar
  • 1,620
0 votes
1 answer
169 views

Bash history wrap around to the earliest, oldest command

How do we have bash history wrap around to the first, oldest command when at the latest, newest command?
user avatar
1 vote
1 answer
383 views

Why print command can not be called with sudo? [duplicate]

% print ok ok % sudo print ok sudo: print: command not found It seems the print are not properly loaded. So what happened and how can I fix it?
Anon's user avatar
  • 405
0 votes
1 answer
113 views

Help with .bash program

I need to add a part to a shell script that will count down the number of command line arguments, printing one per second to the screen and reporting how many command line arguments are left (e.g., by ...
camjace321's user avatar
3 votes
3 answers
837 views

Reversing a file line-wise and character-wise

Input: hello enrico output: ocirne olleh To do this, I can simply tac a file and pipe the output to rev (or the other way around), so one function that does the job is just this: revtac() { tac &...
Enlico's user avatar
  • 1,677
1 vote
1 answer
504 views

How to view all the list that can be viewed by update-alternatives?

Tabbing gives me ls data but i want something to be shown like x-session-manager , x-terminal-emulator and so on. How can i get list what can i set?
Machine Yadav's user avatar
4 votes
2 answers
1k views

Input redirection to for and while

Just out of curiosity, This command works: $ <file cat But neither of these do: $ <file for bash: for: command not found... $ <file while bash: while: command not found... Why is that?
Stalin Vignesh Kumar's user avatar
0 votes
0 answers
22 views

'compgen' appears to have undocumented parameter '--', can I rely on it being present across systems? [duplicate]

I happen to be on Ubuntu 18.04, with GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu) The output of % compgen -A file -- test-data foobar -- outputs all files/dirs in the current directory ...
Craig  Hicks's user avatar
5 votes
1 answer
2k views

How to build loadable builtins for Bash

As I recently learned, it's possible to dynamically load custom builtins into Bash (see enable in the manual, and this answer). However I'm not sure how to take advantage of this feature. The linked ...
dimo414's user avatar
  • 1,807
1 vote
2 answers
139 views

issues Debugging cd on custom shell [closed]

I am having issues with my custom shell cd command I created. Right now I am testing the base case where cd is the only argument, when that is the case its suppose to change the default directory to ...
MegalomaniacGT's user avatar
-1 votes
1 answer
225 views

Manual entry for history missing... `man history` [duplicate]

I'm trying to figure out what's going on with my history... but I can't find the manual history -h returns nothing man history returns a level 8 history manual, not the bash one we all use.
Ray Foss's user avatar
  • 1,012
2 votes
1 answer
107 views

Why can't I see the manual for > but can see it for [?

I just did man [ and it opened the manual. Then I tried doing man > but I get this error: -bash: syntax error near unexpected token `newline' How is > different from [?
Honey's user avatar
  • 126
0 votes
0 answers
194 views

Where is the information of the hash table stored? In other words, where is its database?

The "command hashing system" should store the path of the shell commands somewhere, right ? Is it a database or what? I am wondering where that is. Also, Is it encrypted ? Do we have a way of ...
David's user avatar
  • 309
2 votes
1 answer
298 views

Use bash builtin `bind` command when starting chroot

I have a chroot and I want the chroot to have its own .inputrc file when it starts, and then run a program. I'm used to starting the chroot with chroot <PATH> <PROGRAM_TO_RUN> so I tried ...
Wimateeka's user avatar
  • 1,015
1 vote
1 answer
684 views

print list of environment variable names (without values)

There is a POSIX version of this question elsewhere; for those that don't want to live in a cave, this is the modern version.
todd_dsm's user avatar
  • 317