0

Bash manual says:

An interactive shell is one started without non-option arguments, unless -s is specified, without specifying the -c option, and whose input and output are both connected to terminals (as determined by isatty(3)), or one started with the -i option.

I was wondering which "unless -s is specified" applies to:

  • "without non-option arguments", or
  • "without specifying the -c option"?

Can you rephrase the quote more clearly to enumerate all the ways to start an interactive shell? (I am only clear that I can start one by -i alone, but not sure about the other way(s) which the quote describes.)

Thanks.

4

“unless -s is specified” qualifies “without non-option arguments”. The synopsis for bash is

bash [options] [command_string | file]

Non-option arguments are command_string or file. If you specify either of these, the resulting shell isn’t interactive, unless you specify -s, without specifying -c. -s causes the arguments to be assigned to the positional parameters instead of being interpreted:

bash -s arg1 arg2

opens an interactive shell, and

echo $*

outputs

arg1 arg2

So you can open an interactive Bash shell using either of the following:

  1. ensure the standard input and output are connected to a terminal and specify no non-option arguments;
  2. ensure the standard input and output are connected to a terminal and specify -s with any arguments apart from -c;
  3. specify -i.

If you specify both -c and -s, -c takes precedence (it’s processed earlier). The resulting shell is non-interactive and processes the given command.

  • Thanks. What kind of shell is it, if the standard input and output are connected to a terminal and "specify both -s and -c"? – Tim Apr 5 '18 at 17:36
  • One might do well to refer to unix.stackexchange.com/questions/277312 from 2016 at this point. – JdeBP Apr 5 '18 at 21:16
  • Thanks. Still confused. In "without non-option arguments, unless -s is specified, without specifying the -c option", (1) which is the "unless" clause: "unless -s is specified", or "unless -s is specified, without specifying the -c option"? (2) What does "non-option argument" mean? If an option expects an argument following it, is an argument following it a non-option argument? For example, is "echo hello" in bash -c "echo hello" a nonoption argument? – Tim Apr 6 '18 at 19:35
  • (cont) (2) In bash -c "echo hello", if I am correct, "echo hello" is called an option argument, so there is no nonoption argument and it fits the first bullet point in your reply. But the shell it created isn't interactive. – Tim Apr 6 '18 at 20:03

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.