2

I was reading the Bash manual in order to understand the -s option when invoking bash. The first sentence says:

-s If this option is present, or if no arguments remain after option processing, then commands are read from the standard input.

What does "no arguments remain after option processing" mean? Eventually, all options will be processed and there won't be any options/arguments left to process, right?

I need to know the difference between using bash -s and without (i.e., bash).

2

The following will run script with arguments arg1 and arg2:

bash script arg1 arg2

With -s, something very different happens: an interactive shell is started and any remaining arguments to bash are interpreted not as commands to but only as positional arguments:

$ bash -s arg1 arg2
$ echo "0=$0  1=$1  2=$2"
0=bash  1=arg1  2=arg2

In the above, echo "0=$0 1=$1 2=$2" was typed in by hand at the interactive prompt for the new shell.

  • Do you have a use case in mind where it's powerful ? – Gilles Quenot Feb 27 '18 at 21:48
  • Ah...I think I finally understand what "if no arguments remain after option processing" means. It means there are no arguments other than options. So this implies the two commands bash and bash -s (with no further arguments) are equivalent, and both start interactive shells. Am I right? – flow2k Feb 27 '18 at 21:50
  • @GillesQuenot Sometimes, when testing script commands, I find it useful to have the positional arguments set. I would usually set them, though, with set -- arg1 arg2 rather than bash -s arg1 arg2. So, no, I have no powerful use case. – John1024 Feb 27 '18 at 22:00
  • 1
    @flow2k Yes, as far as I can tell, the commands bash and bash -s, with no additional arguments, are equivalent. – John1024 Feb 27 '18 at 22:02
  • It seems bash and bash -s are also equivalent to bash -i. – flow2k Mar 3 '18 at 21:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.