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

learn more… | top users | synonyms

94
votes
7answers
10k 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?
59
votes
4answers
4k views

Why is `[` a shell builtin and `[[` a shell keyword?

As far as I know, [[ is an enhanced version of [, but I am confused when I see [[ as a keyword and [ being shown as a builtin. [root@server ~]# type [ [ is a shell builtin [root@server ~]# type [[ [[ ...
45
votes
4answers
9k 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 ...
30
votes
6answers
4k 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 ...
27
votes
7answers
6k 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 ...
24
votes
2answers
5k 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 ...
21
votes
5answers
7k views

Why is echo a shell built in command?

$ which echo echo: shell built-in command. $ which ls /bin/ls $ which cat /bin/cat Why is echo not an independent utility like ls, ps, cat etc? Why is it shell specific? Any good reasons?
20
votes
4answers
2k views

What's the difference between eval and exec?

eval and exec are both builtin commands of Bash (1) that execute commands. I also see exec has a few options, but that is the only difference?
19
votes
5answers
4k views

Make bash use external `time` command rather than shell built-in

How can I make bash use time binary (/usr/bin/time) by default instead of the shell keyword? which time returns /usr/bin/time type time returns time is a shell keyword Running time is obviously ...
16
votes
5answers
822 views

Write output of `time` in a file, why are parentheses needed?

time writes to stderr, so one would assume that adding 2>&1 to the command line should route its output to stdout. But this does not work: test@debian:~$ cat file one two three four test@...
13
votes
6answers
498 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. ...
11
votes
1answer
7k views

Understand `compgen` builtin command

From help compgen: $ help compgen compgen: compgen [-abcdefgjksuv] [-o option] [-A action] [-G globpat] [-W wordlist] [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [word] ...
10
votes
4answers
1k views

Why is my program called “set” not being executed?

I've created a simple C program like so: int main(int argc, char *argv[]) { if (argc != 5) { fputs("Not enough arguments!\n", stderr); exit(EXIT_FAILURE); } And I have my ...
9
votes
4answers
346 views

When are the built-in commands loaded to memory

Let's say if I type in cd in my shell. Is cd loaded from the memory at that moment? My intuition is that these built-in commands are pre-loaded to the system memory after the kernel has been loaded, ...
9
votes
2answers
287 views

What is not shell specific?

Under some answers, I see comments that recommend avoiding shell specific commands in answers. How do I know which commands, operators, etc exist in all shells? Is there a list of standards? man ...
9
votes
1answer
630 views

Is “wait &” (“wait ampersand”) a useful (bash) shell / shell script idiom or technique?

I've "inherited" some shell scripts for Linux machines running the GNU "bash" shell. In one particular case, the machine runs GNU bash version 2.0.5b One of those scripts has a wait & ("wait ...
9
votes
1answer
1k views

What is the difference between which and where

What is the difference between where and which shell commands? Here are some examples ~ where cc /usr/bin/cc /usr/bin/cc ~ which cc /usr/bin/cc and ~ which which which='alias | /usr/bin/...
7
votes
2answers
630 views

Order of executables started in bash

If I execute the test command in bash, test(evaluates conditional expression) built-in utility is started: $ type test test is a shell builtin $ type -a test test is a shell builtin test is /usr/...
7
votes
2answers
1k views

Possible to use brace (permutation) and array expansion simultaneously?

Bash's {} brace expansion syntax allows for creating easy permutations # echo {b,c,d}{a,e,i,o,u} ba be bi bo bu ca ce ci co cu da de di do du However it's not clear to me if/how it's possible to ...
7
votes
1answer
452 views

Using the built-in “time” command in bash rather than the external command

Working with the time command, I came across a situation where I should use the built-in time rather than the external GNU time command /usr/bin/time. So, how can I do this? I saw somewhere that ...
7
votes
2answers
2k views

Count number of elements in bash array, where the name of the array is dynamic (i.e. stored in a variable)

Brief statement of the question: Is there built-in bash method to count number of elements in bash array, where the name of the array is dynamic (i.e. stored in a variable), without resorting to ...
6
votes
4answers
349 views

Use case / practical example for Bash' builtin exec

Consider this from the documentation of Bash' builtin exec: exec replaces the shell without creating a new process Please provide a use case / practical example. I don’t understand how this ...
6
votes
3answers
519 views

Why is the manual for 'where' command not available

I recently came across the command where, which provides the actual path of executables in Linux. I was aware of which, whereis, locate and find, but not where. I want to know when this command got ...
6
votes
2answers
189 views

What does “is hashed” mean when using the type command? [duplicate]

I was reading this post and trying out all of the commands in the first answer... I don't really have anything else better to do right now. Anyways, I ran through them all in regards to rm. What ...
5
votes
2answers
315 views

Default preference of executable over built-ins with the same name

I was playing around a bit with the names of some executables, putting them in a folder, ~/bin, which is in my $PATH. Now I'm wondering how I can set the preferences of a bash-3.2 terminal so that it ...
4
votes
3answers
873 views

Why is bash's printf faster than /usr/bin/printf?

I have two ways of calling printf on my system: $ type -a printf printf is a shell builtin printf is /usr/bin/printf $ file /usr/bin/printf /usr/bin/printf: ELF 64-bit LSB executable, x86-64, ...
4
votes
1answer
101 views

What is this HOME command?

I'm able to run a command named "HOME" which appears to be equivalent to cd && echo "~". But I can't figure out where it's defined: $ pwd /tmp $ which HOME HOME not found $ type HOME HOME not ...
4
votes
1answer
318 views

Why are parameters to Bash's builtin optional?

Running simply builtin prints nothing and returns exit code 0. This is in accordance with help builtin, which shows all parameters as optional. But why isn't this no-op an error? Is there a use case ...
4
votes
2answers
1k views

Capture multi-line output of a bash builtin

Normally, bash is able to assign multi-line output of a command: L=`ls` This works from both interactive shell and scripts. But it appears the output of a builtin can't be captured in a variable: ...
4
votes
2answers
270 views

Checking if a command is a built-in in ksh

How can I check if a command is a built-in command for ksh? In tcsh you can use where; in zsh and bash you can use type -a; and in some modern versions of ksh you can use whence -av. What I want to ...
3
votes
2answers
400 views

The type command can't distinguish between an executable command and a shell script

So I was reading the book The Linux Command Line, and it says that commands are of four types: (1) executable programs (2) shell builtins (3) shell functions (shell scripts) (4) ...
3
votes
5answers
1k views

missing man pages of some commands

Typing man alias gives me No manual entry for alias The same thing goes for export and eval. At first I thought it only happens to shell built-in commands but man echo gives me the man page. ...
3
votes
3answers
4k views

Why does my shell script give the error: “declare: not found”?

Here is a simple example showing that using declare in a script the script will not run, while sourcing the script will: $ cat /tmp/new #! /bin/sh declare -i hello $ chmod a+rwx /tmp/new $ /tmp/new /...
3
votes
2answers
1k views

How to invoke a shell built-in explicitly?

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

the return built-in

According to the Open Group, [t]he return utility shall cause the shell to stop executing the current function or dot script. If the shell is not currently executing a function or dot script, ...
3
votes
2answers
44 views

Why builtin times doesn't work in pipeline?

I've the following sample script: #!/usr/bin/env bash sleep 5 printf "times cmd: " times printf "pipeline: " times | ( read user sys; echo $user; ) printf "head: " times | head -n1 printf "times cmd ...
3
votes
1answer
276 views

strace works for some builtin commands

I'm trying to understand some kernel level concepts in Linux. I was checking on the difference between shell builtin commands and the other executable commands. This wonderful answer clearly tells ...
2
votes
3answers
322 views

In bash, how can I erase an alias without logout? [duplicate]

I had an alias in my .bashrc and I really don't want it anymore. I erased the alias, but my bash already has this alias loaded. Can I erase this alias from this bash without logging out?
2
votes
3answers
1k views

how does built in commands of a shell implemented in Linux? as a function or thread of shell process?

I know that external commands are run in the shell by creating a separate process. But what exactly happens when a built in command is run in a shell. Are they executed as a function or if the shell ...
2
votes
6answers
538 views

bash equivalent of this use of tcsh “sched” command?

In tcsh, the built-in sched command causes a command to be executed by the current shell at a specified time. I have the following $HOME/.sched file (this is a simplified version of it): setenv ...
2
votes
2answers
3k views

Why does Bash's “source” command behave differently when called from a function?

Given the following sourceable bar Bash script ... echo :$#:"$@": ... and the following executable foo Bash script: echo -n source bar: source bar echo -n source bar foo: source bar foo function ...
2
votes
2answers
236 views

Set shell environment variable without using a shell builtin command

I am using a program that takes a "command" as an argument and then adds some helpful wraping around it. Presumably in an effort to be helpful it appears to checks to make sure the command "exists". ...
2
votes
1answer
4k views

A command that gives username@hostname:pwd

I know that pwd gives the current working directory, hostname gives the current host and whoami gives the current user. Is there a single unix command that will give me the output of whoami@hostname:...
2
votes
1answer
45 views

How can I get a help message for zsh builtin's?

If I want to get a brief usage message for a bash builtin, I can use help <builtin> at a command prompt, e.g. $ help export export: export [-fn] [name[=value] ...] or export -p Set export ...
2
votes
1answer
69 views

Pipelines, Jobs and Processes in Zsh

I went through the Jobs & Signals documentation in Zsh, but some things aren't still clear to me. It says: If the MONITOR option is set, an interactive shell associates a job with each ...
2
votes
1answer
1k views

What is the difference between the built in echo command and /bin/echo? [duplicate]

I was playing around with the type and which commands and I discovered something strange. type either returns the path or says that a command is a Bash built in. which either returns the path or ...
2
votes
1answer
2k views

Bash pipe output to more

I am wondering about some bash environment setting here: is it possible to set stdout of bash as a pipe to /bin/more? You know, like using vi as editor for your commands it should be possible to avoid ...
2
votes
1answer
207 views

An -e option to cd builtin

According to Bash reference on Bash builtins: cd [-L|[-P [-e]]] [directory] The -P option means to not follow symbolic links; symbolic links are followed by default or with the -L option. ...
1
vote
1answer
69 views

linux how to cd to parent folder if navigated through a symlink [duplicate]

I have following symlink in my home directory. lrwxrwxrwx 1 mtk mtk 43 Aug 8 20:35 tripple-bit -> /media/mtk/study/Collage/docs I use the symlink to navigate to the docs folder directly. But ...
1
vote
2answers
143 views

Are there any pitfalls to overriding ls?

Is there anything to watch out for if you wanted to override ls? Is there a more reliable way of getting pagination out of ls? For example: function ls() { command ls -hp $@ | more; }