根据bash手册页,它说-i
是用于shell的交互模式。我尝试了示例代码来找出-i
选项的作用。interactive.sh是需要用户输入的脚本,这意味着交互脚本。
默认的bash选项是非交互模式,但是interactive.sh在非交互模式下运行没有任何问题,在交互模式下也运行良好,这让我很困惑。
bash中-i
选项的确切用法是什么?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
1条答案
按热度按时间92vpleto1#
使用
bash -i script
,您将运行交互式非登录shell。qbash中-i选项的确切用法是什么?
从
man bash
开始:shell中交互模式和非交互模式的区别是什么?
有一些不同之处,请看
man bash | grep -i -C5 interactive | less
:[...]
例如
bash -i -c 'echo $PS1'
。