According to bash man page, it says -i
is for interactive mode of shell.
I tried example code to find out what -i
option does.
interactive.sh is script that needs user input, which means interactive script.
The default bash option is non-interactive mode. But the interactive.sh runs without any problem with non-interactive mode. It also runs well with interactive mode. It confuses me.
What is the exact usage of -i
option in bash?
What is the difference between interactive and non-interactive mode in shell?
$cat interactive.sh
#!/bin/bash
echo 'Your name ?'
read name
echo "Your name is $name"
$ bash interactive.sh
Your name ?
ABC
Your name is ABC
$ bash -i interactive.sh
Your name ?
DEF
Your name is DEF
With
bash -i script
you are running interactive non-login shell.qFrom
man bash
:There are some differences. Look at
man bash | grep -i -C5 interactive | less
:[...]
etc. For example
bash -i -c 'echo $PS1'
.