Linux Format

A QUICK REFERENCE TO… SHELL BUILT-INS

-

Sometimes you may execute a shell command and find that its behaviour doesn’t match that of the man page. This is because most shells, like Bash and ZShell, have duplicates of a number of core commands built in. This is done for speed and efficiency: the command doesn’t have to be loaded from disk before it can be used – it’s already loaded as part of the shell. You can find a list of built-in commands in the man page for your shell (the bash man page is long, but the informatio­n is in there). You can tell if a command is a built-in one or not with the type command: $ type cd cd is a shell builtin

$ type tar tar is /bin/tar

So what do you do if you want to run the “standard” version of the command rather than the built-in one? That’s easy, you just give the full path, say /usr/bin/

command, and it will be called from disk.

Aliases are also used to make life easier for shell users and most distributi­ons have a number predefined. You can see them all by running alias

with no arguments. In some cases, an alias has the same name as the command that it’s calling, for example, many distros alias ls to ls --color=auto

to give coloured output by default. Running the original version is as simple as prefixing the command name with a backslash, which tells the shell to ignore any alias of that name, such as

$ \ls somedir

The man pages for the various shells are pretty heavy going, but it’s worth spending some time going through them if you use the shell with any regularity. The nuggets that you’ll find in there could save you more time than you spend looking for them.

Newspapers in English

Newspapers from Australia