Bourne to Bourne Again Shell Forward Compatibility

Reserved Words

Bash has more reserved words than Bourne Shell. For example, the following code executes with no errors in sh:

select() { echo "select!" ; }

It can then be executed, generating the expected output, by issuing the function name as a command:

select

In bash, this code conflicts with the built-in command named „select“. The definition of a function with a name of „select“ will render an error: -bash: syntax error near unexpected token `('

Note that the error is not caused by Bash preventing the user from overriding select (it does not), but by the Bourne Shell syntax of a function definition (funcname() { commands ... }) leading to an incorrect invocation of the select command. You could still override the command with an own function using the Bash-specific syntax:

function select() { echo "select!" ; }

You could then execute that function by quoting the reserved word:

'select'

If not quoted, select would still appear to the interpreter as a control flow statement:

select v in x y z ; do echo $v ; break ; done

Again, this form of function definition is Bash-specific, and the code will not run in Bourne Shell anymore.

Advice

When planning to port a script from sh to bash, functions with names that are reserved words in bash, but not in sh, must be renamed.

The online manual of Bash has an index of reserved words:

For comparison, a list of reserved words of POSIX Shell is contained in POSIX.1-2017, Base Specification, Shell & Utilities: