On Sunday, January 13, 2013 11:05:36 AM Mart Frauenlob wrote:
> Hello,
>
> I was wondering what the proposed usage of `$-' is?
> I thought it will show me all current set flags, but it is excluding
> some like posix.
> The reason for this question is, that I wanted to detect if a script is
> ran in posix mode. Detect that and print a warning.
> But there doesn't seem to be a representation of -o posix|--posix in $-.
>
> $ /opt/bash42/bin/bash +o posix -c 'echo $-'
> hBc
> $ /opt/bash42/bin/bash --posix -c 'echo $-'
> hBc
>
> Thanks for your help
>
> Mart
>
- only contains the options representable by short option flags to set. The
value you're looking for is in SHELLOPTS. [[ $SHELLOPTS == *posix* ]]. There
are some extra differences depending upon how "POSIX mode" was set but most
shouldn't have to worry about them (echo can be more or less strict for
instance).
I would not worry about it too much unless the script is meant to be sourced.
A /bin/bash shebang should be sufficient otherwise.
--
Dan Douglas