【发布时间】:2020-05-14 17:38:41
【问题描述】:
我的主文件是 main.sh:
cd a_folder
echo "executing another script"
source anotherscript.sh
cd ..
#some other operations.
另一个脚本.sh:
pause(){
read -p "$*"
}
echo "enter a number: "
read number
#some operation
pause "Press enter to continue..."
我想跳过暂停命令。但是当我这样做时:
echo "/n" | source anotherscript.sh
它不允许输入数字。我希望出现“/n”,以便允许用户输入数字但跳过暂停语句。
PS:不能在 anotherscript.sh 中做任何更改。所有更改都在 main.sh 中完成。
【问题讨论】:
-
I wanted to skip the pause command是什么意思?你能详细说明一下吗?暂停是用户定义的功能吗?你想通过修改main.sh来绕过 -
没错,@Inian。相应地编辑了我的描述。
-
要输出回车而不是
echo "/n",您需要使用printf "\n",使用反斜杠而不是斜杠,或者最好只使用不带参数的echo。 -
考虑
source anotherscript.sh < <(printf '\n' '1234' ''),它避免了需要causes the code to besourceed in a completely different shell 的管道,从而破坏了首先使用source的意义。
标签: bash macos terminal iterm2 iterm