Force POSIX mode

Bash can be told to disable brace expansion with set +B, which is the inverse of set -B:

-B The shell will perform brace expansion (see Brace Expansion). This option is on by default.

You can also provide this on the command line when launching the shell:

$ bash +B -c 'echo {a,b,c}'
{a,b,c}

You can combine this with the --posix or set -o posix options to get closer to fully-POSIX behaviour. You also need to enable shopt -s xpg_echo at least.

There will be other corners as well — many of the extensions are quite deeply-ingrained — and I don't think it's possible to get Bash to support only the behaviour that is actually mandated by POSIX. Even dash doesn't manage that.

However, you may find dash (the default /bin/sh on Debian) more helpful if you're aiming to avoid extended behaviours, although it supports some extensions as well. There is also BusyBox's ash applet, which also has some extensions, but many can be disabled statically.

Tags:

Shell

Bash

Posix