【发布时间】:2019-05-04 18:15:30
【问题描述】:
我尝试从 script2.sh 运行 script1.sh 并回答脚本 1 的提示。
在script1.sh中:
echo "Do you wish to save these settings?"
read response
if [ $response = "yes" ]
then
echo "Settings saved"
elif [ $response = "no" ]
then
echo "Settings not saved"
fi
echo "Would like to end"
read response2
if [ $response2 = "yes" ]
then
echo "Bye"
elif [ $response2 = "no" ]
then
echo "OK"
fi
在script2.sh中:
sh "/home/username/Desktop/script1.sh"
我想要它,这样每当我尝试运行 script2.sh 时,它会自动为 script1.sh 的两个提示输入是或否。
【问题讨论】:
-
一个更好的设计(这将使您的原始问题标题正确,尽管我现在看到有人对其进行了更新)是将选项作为命令行参数传递。