Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is a FreeBSD 7.x system running GNU bash version 4.0.

In Bash, the set -u option can force a shell to print an error if it encounters an unset variable, like this:

$ set -u
-su: THISISUNSET: unbound variable
$ echo $?

However, I am also encountering this same error for $*:

$ echo $*
-su: $*: unbound variable
$ echo $?
$ echo $@
-su: $@: unbound variable

The Bash Manual 4.3.1 The Set Builtin specifically says that set -u ignores $* and $@:

-u Treat unset variables and parameters other than the special parameters ‘@’ or ‘*’ as an error when performing parameter expansion. An error message will be written to the standard error, and a non-interactive shell will exit.

How can I fix this?

share|improve this question
up vote 6 down vote accepted

This is a bug in older versions of bash, specifically 4.0​β2 patchlevel d to 4.0 patchlevel m. From the changelog from 4.0 to 4.1​α:

n. Fixed the behavior of set -u to conform to the latest Posix interpretation: every expansion of an unset variable except $@ and $* will cause the shell to exit.

This behavior was introduced in ​4.0β2 because the previous (and now again current) behavior was thought to be buggy:

d. Fixed a bug that caused expansions of $@ and $* to not exit the shell if the -u option was enabled and there were no posititional parameters.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.