Shell Built-in and Commands

Shell Built-in

Shell Built-in does not request another program to run a process because it is a shell built-in. so use shell built-in if it is available.

A built-in command is simply a command that the shell carries out itself, instead of interpreting it as a request to load and run some other program. This has two main effects. First, it's usually faster, because loading and running a program takes time. Of course, the longer the command takes to run, the less significant the load time is compared to the overall run time (because the load time is fairly constant).

Keywords

Keywords are the words whose meaning has already been explained to the shell. the keywords cannot be used as variable names because it is a reserved word containing reserved meanings.

Sequence

when you run a command bash will search a function with the same name if the function with the same name is not present then bash will search it in builtins. if builtin is also not available then it will search the command at PATH locations.

┌──(gaurav㉿learning-ocean)-[~]
└─$ uptime
 01:37:53 up 2 min,  2 users,  load average: 0.60, 0.59, 0.26

┌──(gaurav㉿learning-ocean)-[~]
└─$ type -a uptime
uptime is /usr/bin/uptime
uptime is /bin/uptime

┌──(gaurav㉿learning-ocean)-[~]
└─$ type -a echo
echo is a shell builtin
echo is /usr/bin/echo
echo is /bin/echo

┌──(gaurav㉿learning-ocean)-[~]
└─$ type -a pwd
pwd is a shell builtin
pwd is /usr/bin/pwd
pwd is /bin/pwd

┌──(gaurav㉿learning-ocean)-[~]
└─$ type -a if
if is a reserved word

┌──(gaurav㉿learning-ocean)-[~]
└─$ echo $PATH
/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/kali/.dotnet/tools