Built-Ins
The „built-ins“, commands that are implemented by the shell itself, are no reserved words in bash; for example, it is entirely possible to declare a function called „shopt“ in Bourne Again Shell:
shopt() { echo "shopt!" ; }
shopt
It is not advisable to use such identifiers in a bash script; in above example it would obscure the genuine built-in named „shopt“. The built-in „shopt“ still was accessible using the built-in named „builtin“:
builtin shopt -s execfail
One could imagine that this was not a definite solution, because the built-in named „builtin“ could be obscured by a user-defined function of the same name, until the function named „builtin“ was undefined using unset -f builtin, this again only unless the built-in „unset“ was obscured by a user-defined function of the same name, and so on …
Note that there is an ultimate escape from a bash session where built-ins have been obscured by user definitions (thanks to sdk for pointing this out to me). Setting the environment variable POSIXLY_CORRECT will suppress any own definitions obscuring reserved words. The following sequence of command lines in bash demonstrates this:
set() { echo "set!" ; }
unset() { echo "unset!" ; }
set
unset
POSIXLY_CORRECT=
unset set
unset POSIXLY_CORRECT
set
Advice
- Do not use names of built-ins as names for your own functions.
- Keep in mind that bash makes little effort to prevent this, and that there are many such names, as can be seen in the documentation of GNU Bash:
- GNU find hat keine Option „-older“ …
- Bourne to Bourne Again Shell Forward Compatibility
- Print XDG Desktop Definition for Application
- Find Files by Size given in Bytes
- Using sed or awk to ensure a specific last Line in a Text
- Make a Bourne Again Shell Script Log its Output to a File
- Maintaining Multi-Line „stat“ Formats using Bourne Again Shell
- Print all indented Lines following a non-indented Line