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
2answers
67 views

Why does the command 'source' have that name?

I wonder why a command that executes commands from a file in the current shell is named source. I can't see a relation between run commands in the current shell and the meaning of the english word ...
48
votes
2answers
11k views

Can I get individual man pages for the bash builtin commands? [duplicate]

Is there anywhere you can download a manpage for every builtin commands? I know you can just use help or man bash and search to find info about it, but I want them separated, so I can just do man ...
5
votes
3answers
727 views

What is “declare” in Bash?

After reading ilkkachu's answer to this question I learned on the existence of the declare (with argument -n) shell built in. help declare brings: Set variable values and attributes. Declare ...
0
votes
1answer
42 views

How to know from which bash version a built-in is made available?

Is it possible to know from which specific version of bash a particular built-in is made available from the command-line? Is it only possible by browsing through release notes for each of the versions ...
1
vote
1answer
31 views

How do I return octal from Bash's arithmetic expansion?

As clearly spelled out in the Bash documentation on shell arithmetic, if you prefix a number with a 0 within an arithmetic expansion expression (e.g., $(( expr ))), it's treated as octal. Similarly, ...
0
votes
0answers
36 views

Examples of common programs

Is there a some man-like program (or site/book) that can show me simple examples of common tools usage? So i can type in terminal show-example grep and it will output ... For matching multiple ...
6
votes
3answers
425 views

Shell builtin `printf` line limit?

The /usr/bin/printf util argument list length is limited to the shell's maximum command line length, (i.e. getconf ARG_MAX, on my system that'd be 2097152); example: # try using a list that's way too ...
8
votes
4answers
641 views

Bash Read: Reading comma separated list, last element is missed

The output of the command below is weird to me. Why does it not give me back element 5? $ echo '0,1,2,3,4,5' | while read -d, i; do echo $i; done 0 1 2 3 4 I would expect '5' to be returned as well. ...
73
votes
4answers
82k views

What's the difference between eval and exec?

eval and exec are both built in commands of bash(1) that execute commands. I also see exec has a few options but is that the only difference? What happens to their context?
2
votes
2answers
73 views

What's the POSIX specification on behavior of built-in commands with redirections and/or piping?

Consider the following commands: exit > /dev/null exit | cat On a few shells (ksh, bash, (d)ash), the behavior is the same: The first command causes the shell to quit immediately, while the ...
42
votes
7answers
10k views

What purpose does the colon builtin serve?

I've hacked on a lot of shell scripts, and sometimes the simplest things baffle me. Today I ran across a script that made extensive use of the : (colon) bash builtin. The documenation seems simple ...
-2
votes
1answer
170 views

Shell Script for formatted output [closed]

06/26/2017 23:40:40 CAUAJM_I_10082 [aspsun14 connected for IOALPPRXXBD_ALPGLGENFAALL 55443.15215291.1] 06/26/2017 23:40:40 CAUAJM_I_40245 EVENT: CHANGE_STATUS STATUS: STARTING ...
3
votes
2answers
211 views

Issue with type force PATH search

This is Bash. The behavior is similar in fish. $ which python /usr/bin/python $ alias py=python $ type py py is aliased to `python' ​And then, running type -P py prints nothing, where as I expected ...
3
votes
1answer
94 views

Why does `kill` not appear to be a Bash builtin? (it should be) [closed]

The Internet is unanimous: kill is a Bash builtin. Bash changelog says the same. However my other builtins apparently think otherwise: $ builtin kill bash: builtin: kill: not a shell builtin $ type ...
0
votes
2answers
48 views

How can i echo the value of [ 4 -gt 3 ] ,that is a test expression in bash?

How can I echo the value of [ 5 -gt 4 ] ,that is a test expression in bash? [ 5 -gt 4 ] | echo and echo `[ 5 -gt 4 ]` both end up printing a blank line @Thomas Dickey 's answer works but could ...
13
votes
4answers
5k views

How to invoke a shell built-in explicitly?

I want to customize the functionality of cd command as per my needs. I defined the following function - function cd () { cd "$@" && pushd "$@"; } The intent of this function is to ...
2
votes
1answer
62 views

Documentation on bash completion

I've been unable to find complete documentation for the complete and compgen bash builtin commands. I'm on a Macintosh and help complete produces complete: complete [-abcdefgjksuv] [-pr] [-o option] ...
18
votes
2answers
1k views

Why does POSIX require certain shell built-ins to have an external implementation?

From this question about whether printf is a built-in for yash, comes this answer that quotes the POSIX standard. The answer points out that the POSIX search sequence is to find an external ...
13
votes
3answers
604 views

Slightly confused about whether printf in the yash shell is a built-in command or not

The yash shell has a printf built-in, according to its manual. However, this is what I see in a yash shell with default configuration: kk@eeyore ~ $ command -v printf /usr/bin/printf kk@eeyore ~ $ ...
1
vote
0answers
39 views

Command to list all reserved words [duplicate]

Is there a command to list all reserved words? I'm aware of resources such as the GNU reserved word index, but what I'm looking for is a command that gives me this information for my shell on the ...
1
vote
3answers
83 views

Shell: only double quote on test -n/-z? [duplicate]

In case of test -e for example: VAR="<this is a file path: /path/to/file/or/dir" test -e $VAR && do_something || do_anotherthing Question: Should I use "$VAR" here?, here I don't like ...
0
votes
1answer
40 views

How can I extract a function from bash/zsh with all its shell-related dependencies?

I write a lot of little useful functions, and sometimes I like to share them with friends or the world. The problem is that I use a lot of my helper functions and aliases in my functions, and I don't ...
2
votes
3answers
123 views

How can I view the stack used by `pushd` and `popd`?

I would like to use the recently accessed directories list for logging purposes. Is the directory stack as used by pushd and popd stored somewhere, perhaps as a list of folders in a text file? If so, ...
1
vote
1answer
845 views

Password Encryption [duplicate]

I have a Migrate.ksh file, in that some passwords are available, I would like to encrypt this file in the Unix. The Passwords file being used in another script. Can you please let me know the process ...
-3
votes
2answers
178 views

rm -rf ./* deletes content of current directory only partially [duplicate]

rm -rf ./* deleted all content of current directory only partially. Input: MN> cd ~/mydir MN> rm -rf ./* MN> ll Output: -rw-r--r-- 1 MN MN 1025 Aug 1 15:50 .file1 -rw-r--r-- 1 MN MN ...
0
votes
1answer
69 views

How bash builtins works with pipeline

Bash builtins defines as: The shell executes the command directly, without invoking another program. And a pipeline like foo | bar works roughly like: bar waits inputs from foo, and foo exits ...
0
votes
1answer
152 views

Does a Linux command called (h) exist?

I read in an unofficial documentation about a Linux shell command called h: it was mentioned together with the help and man commands, without any explanation. So I tried it on my linux terminal but it ...
0
votes
0answers
25 views

send stdin to stderr for a time, then stop after timeout and discard: gnu textutils?

We have a very chatty application which says useful things during startup but then refuses to be quiet (useful logs are sent elsewhere). This interacts problematically with log rotation, snapshotting, ...
-2
votes
1answer
86 views

Does a shell builtin command actually run the program from its path?

I was reading the marked answer from here : What is the difference between a builtin command and one that is not? Here he says : A built-in command is simply a command that the shell carries out ...
-1
votes
2answers
155 views

Wait command works when pid doesn't exists

I'm facing an unexpected behaviour of the wait builtin. ~ ❯ sleep 1 & [1] 72009 ~ ❯ [1] + 72009 done sleep 1 ~ ❯ wait 72009 ~ ❯ echo $? 0 Although the PID doesn't exist anymore wait ...
0
votes
2answers
37 views

getting only the path out of `type -p prog` command

if I run nrolland@mactoasty ~ $ type -p skhd skhd is /usr/local/bin/skhd I can't compose it nicely with other command like nrolland@mactoasty ~ $ la `type -p skhd` ls: is: No such file or ...
9
votes
2answers
2k views

Understanding shell builtin commands

In in the bash manual, it's written that Builtin commands are contained >>> within <<< the shell itself Also, this answer states that A built-in command is simply a command that ...
-4
votes
4answers
188 views

Is there a bash builtin command which can show the environment variables of the current shell?

env and printenv are both external commands i.e. executable files, not bash builtins. The problem with them is that some environment variables (such as _, and I also wonder if there are more) which ...
6
votes
2answers
820 views

How to bypass bash functions called `command`, `builtin` and `unset`?

I am aware that aliases can be bypassed by quoting the command itself. However, it seems that if builtin commands are "shadowed" by functions with the same names, there is no way to execute the ...
17
votes
6answers
2k views

Use system command instead of Bash builtin without specifying the full path

I use Bash as my interactive shell and I was wondering if there was an easy way to get Bash to run a system command instead of a shell builtin command in the case where they both share the same name. ...
1
vote
1answer
194 views

How to capture stderr of a bash keyword (e.g. time)?

I want to time reading bash history and put the result into a variable. Unfortunately, time (which is a shell keyword) prints the result to stderr, and apparently redirecting stderr from shell ...
1
vote
2answers
927 views

How to specifically run a shell builtin command

Consider a situation that I run these commands in my current shell or I put them inside .bashrc: alias source='echo hi' alias .='echo hi' alias unalias='echo hi' Or function source(){ echo hi; }, ...
3
votes
1answer
280 views

Need for the `builtin` builtin

What's the point of the builtin builtin when the command builtin has the exact same functionality when it comes to looking up builtins? When making sure that a particular builtin is chosen over a ...
33
votes
6answers
7k views

Is 'cat' a shell built-in or an external program?

When I use the type command to find out if cat is a shell built-in or an external program I get the output below: -$ type cat cat is hashed (/bin/cat) -$ Does this mean that cat is an external ...
1
vote
0answers
72 views

Would a 'function_not_found_handle ()' loadable bash builtin be possible?

I wrote a function to handle unknown commands in bash via command_not_found_handle (). My intention is to source scripts on demand and access its functions inside the handler. But unfortunately the ...
-6
votes
1answer
46 views

`declare` un-causing problems with missing functions/commands?

summary: If in bash I attempt to assign the output of a missing function to a previously-declared (i.e., not {constant, read-only}) variable, I can detect the failure with "normal" tests. But if I ...
3
votes
1answer
167 views

What do special characters stand for in echo {A..z}

I know we can print a sequence of letters of the Alphabet using echo command and experimented it a little by doing this. Lowercase letter Sequence $ echo {a..z} a b c d e f g h i j k l m n o p q r s ...
1
vote
1answer
290 views

dirs -v does not list the directory stack?

I have seen How do I use pushd and popd commands? , and I am aware that with pushd <dir> I would push <dir> to the directory stack, with popd I would pop the top directory from the ...
72
votes
4answers
21k views

What is the difference between a builtin command and one that is not?

Is there any intrinsic difference between a builtin command and another command which can nominally do the same thing? eg. Do builtins get "special" treatement? ... is there less overhead running ...
-1
votes
1answer
55 views

What is the difference between shell builtins and shell keyboard shortcuts?

What is the difference between shell builtins (like cd or echo) and shell keyboard shortcuts (like ctrl+u or ctrl+l)? Both seems to me "builtins", what is the major difference by means of system ...
1
vote
0answers
27 views

What is the behavior of `command`? [duplicate]

According to this comment which is in defense of the author's answer, @einpoklum Yes, it is necessary. In fact, even this solution may break in one edge case. Thanks for bringing this to my ...
127
votes
7answers
19k views

Why is cd not a program?

I've always wondered why cd isn't a program, but never managed to find the answer. Anyone know why this is the case?
2
votes
1answer
28 views

Efficient stdin generation in shell script

Is there a more idiomatic way to express the following? xargs -r -l1 -I % bash -c 'cat <(echo %)' Where cat stands for intended program that does not accept relevant argument from command line, ...
0
votes
4answers
2k views

How can I `man print`?

Where can I find more information about the command(?) print since I don't receive a result when I input man print? For example, in the zsh I can do the following: $ print "Hello, world\!" Hello, ...
0
votes
2answers
185 views

When a shell runs a builtin, and a signal is generated by keyboard, what will handle the signal?

Please correct me if I am wrong: When a bash shell runs an external executable program, the bash shell will create a child process to run the program in foreground. If there is any key-generated ...