1

I have read the following in this question:

A shell running a script is always a non-interactive shell, but the script can emulate an interactive shell by prompting the user to input values.

I don't know if the above statement is correct, I thought the following is correct:

  • A shell running a script and this script allows you to input data is an interactive shell (and not an "emulation" of an interactive shell like the quote says).

  • A shell running a script and this script does not allow you to input data is a non-interactive shell.

Which statement is correct?

  • 1
    Interactivity of a shell has to do with how said shell was started, not with how you enter data. – Satō Katsura Sep 23 '17 at 15:49
1

A shell running a script is a non-interactive shell.

A non-interactive shell can still use e.g. read to read data from standard input.

If standard input is a terminal, this may provide a level of "interaction", but it does not make the shell executing the script an interactive shell. Thu script will be "interactive" though.

The text is confusing because it uses the word "interactive" to mean two things:

  1. A shell that was started in order to execute a shell script is non-interactive (in the sense that it does not have job control, it does not provide a prompt by itself by default etc. etc.). This is a technical term for the type of a shell, just like "login shell" and "interactive shell".
  2. The action of acquiring data by this same script may be "interactive" (if not reading from e.g. a pipe or a file). But then again, any command that takes data from standard input may be said to be interactive. tr 'a-z' 'A-Z' will, by itself, "interactively" turn all lowercase ASCII characters to uppercase.
  • If I opened Terminal and Terminal is using the bash shell, now I am using an interactive shell. Now say I executed a script using the same bash shell that Terminal is using, while the script is being executed, do we say that bash has become a non-interactive shell, or is it the script itself that is a non-interactive shell? – Tom Sep 23 '17 at 16:17
  • @Tom No. The interactive shell is giving over control to a non-interactive shell. You are now dealing with two shells (two shell processes). Both are bash shells, but one is interactive (the one you started the script from, which is now waiting for the script to finish), and one is non-interactive (the one running the script). – Kusalananda Sep 23 '17 at 16:20
  • You are right, I tested executing a script and a new bash process was created. So basically a shell that executes a script is called non-interactive because I really can't send anything to the shell (when the script is using read and I send some text from the terminal, it is the script that will eventually handle this string and not the shell), correct? – Tom Sep 23 '17 at 17:38
  • @Tom I would say that this is a correct understanding, yes. Mostly. It is correct enough. :-) – Kusalananda Sep 23 '17 at 17:40

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.