Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check if Bash POSIX Mode is enabled?

Tags:

bash

Bash Reference Manual:

Starting Bash with the --posix command-line option or executing ‘set -o posix’ while Bash is running will cause Bash to conform more closely to the POSIX standard by changing the behavior to match that specified by POSIX in areas where the Bash default differs.

like image 642
Max Yaskov Avatar asked Dec 18 '25 18:12

Max Yaskov


1 Answers

For interactive use,

set -o | grep posix

...will emit something like:

posix           off

For programmatic use, just enable or disable it (with set -o posix or set +o posix respectively) as suits your needs; there's little reason to ever check the prior value. That said, if you really want to, you can check SHELLOPTS:

case :$SHELLOPTS: in
  *:posix:*) echo "POSIX mode enabled" ;;
  *)         echo "POSIX mode not enabled" ;;
esac
like image 60
Charles Duffy Avatar answered Dec 20 '25 11:12

Charles Duffy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!