Discussion:
[Help-bash] Clarify the meaning of 's' in $- and the meaning of -s when invoking bash
z***@medialab.sissa.it
2017-03-16 07:27:53 UTC
Permalink
Hello all,

It seems to me that the 's' flag is supposed to be shown in $- when
bash reads the standard input. Such a case occur when bash is invoked
with the -s option. Example:

$ echo 'echo $-' | bash -s
hBs

However, bash reads the standard input also when there are no more
arguments after option processing. Example

$ echo 'echo $-' | bash
hB

Can somebody explain what is the difference between running bash with
or without '-s'?

Thank you in advance
Cristian.


btw:

Another case when bash reads the standard input is when simply
started with the command

$ bash
Greg Wooledge
2017-03-16 12:19:00 UTC
Permalink
Post by z***@medialab.sissa.it
It seems to me that the 's' flag is supposed to be shown in $- when
bash reads the standard input.
Err... not exactly. It's included in $- if and only if the -s option
is enabled.
Post by z***@medialab.sissa.it
$ echo 'echo $-' | bash -s
hBs
However, bash reads the standard input also when there are no more
arguments after option processing. Example
$ echo 'echo $-' | bash
hB
Can somebody explain what is the difference between running bash with
or without '-s'?
Nothing. Your script will not operate any differently. The -s option,
as the man page says, "allows the positional parameters to be set when
invoking an interactive shell."
Post by z***@medialab.sissa.it
Another case when bash reads the standard input is when simply
started with the command
$ bash
What are you actually trying to DO?

Are you trying to determine whether stdin is a terminal, inside a script,
or function? If so, you simply use test -t 0 (or any of its equivalents).
Stephane Chazelas
2017-03-16 13:16:32 UTC
Permalink
2017-03-16 08:27:53 +0100, ***@medialab.sissa.it:
[...]
Post by z***@medialab.sissa.it
It seems to me that the 's' flag is supposed to be shown in $- when
bash reads the standard input. Such a case occur when bash is invoked
$ echo 'echo $-' | bash -s
hBs
However, bash reads the standard input also when there are no more
arguments after option processing. Example
$ echo 'echo $-' | bash
hB
[...]

That was a non-conformance (or at least deviation from every
other Bourne-like shell) of bash. It was fixed in 4.4

$ echo 'echo $- $BASH_VERSION' | bash
hBs 4.4.11(1)-release

IIRC, that was discussed last year either on the Austin group or
bug-bash mailing list.
--
Stephane
Cristian Zoicas
2017-03-16 15:08:30 UTC
Permalink
Post by Stephane Chazelas
[...]
Post by z***@medialab.sissa.it
It seems to me that the 's' flag is supposed to be shown in $- when
bash reads the standard input. Such a case occur when bash is invoked
$ echo 'echo $-' | bash -s
hBs
However, bash reads the standard input also when there are no more
arguments after option processing. Example
$ echo 'echo $-' | bash
hB
[...]
That was a non-conformance (or at least deviation from every
other Bourne-like shell) of bash. It was fixed in 4.4
$ echo 'echo $- $BASH_VERSION' | bash
hBs 4.4.11(1)-release
IIRC, that was discussed last year either on the Austin group or
bug-bash mailing list.
Stephane, thank you for your prompt reply.
Cristian
Chet Ramey
2017-03-16 19:01:21 UTC
Permalink
Post by Stephane Chazelas
That was a non-conformance (or at least deviation from every
other Bourne-like shell) of bash. It was fixed in 4.4
$ echo 'echo $- $BASH_VERSION' | bash
hBs 4.4.11(1)-release
IIRC, that was discussed last year either on the Austin group or
bug-bash mailing list.
It had to be austin-group-l. In any case, that behavior is now explicitly
unspecified:

http://austingroupbugs.net/view.php?id=1039#c3617
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU ***@case.edu http://cnswww.cns.cwru.edu/~chet/
Stephane Chazelas
2017-03-17 12:36:44 UTC
Permalink
[...]
Post by Chet Ramey
Post by Stephane Chazelas
IIRC, that was discussed last year either on the Austin group or
bug-bash mailing list.
It had to be austin-group-l. In any case, that behavior is now explicitly
http://austingroupbugs.net/view.php?id=1039#c3617
[...]

Actually, the discussion I was thinking of was from 2015, and I
had totally forgotten that I was the one bringing it up in the
first place. Ouch :-)

http://thread.gmane.org/gmane.comp.standards.posix.austin.general/11313
--
Stephane
Loading...