help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Proposed usage of $-


From: Dan Douglas
Subject: Re: [Help-bash] Proposed usage of $-
Date: Sun, 13 Jan 2013 12:38:09 -0600
User-agent: KMail/4.8.3 (Linux/3.4.6-pf+; KDE/4.8.3; x86_64; ; )

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]