Bourne to Bourne Again Shell Forward Compatibility

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