如何为选择提供一个条目来给出结果,当我在终端中运行代码时,它工作得很完美,代码是:
PS3="Enter the space shuttle to get quick information : "
# set shuttle list
select shuttle in columbia endeavour challenger discovery atlantis enterprise pathfinder
do
case $shuttle in
columbia)
echo "--------------"
echo "Space Shuttle Columbia was the first spaceworthy space shuttle in NASA's orbital fleet."
echo "--------------"
;;
endeavour)
echo "--------------"
echo "Space Shuttle Endeavour is one of three currently operational orbiters in the Space Shuttle."
echo "--------------"
;;
challenger)
echo "--------------"
echo "Space Shuttle Challenger was NASA's second Space Shuttle orbiter to be put into service."
echo "--------------"
;;
discovery)
echo "--------------"
echo "Discovery became the third operational orbiter, and is now the oldest one in service."
echo "--------------"
;;
atlantis)
echo "--------------"
echo "Atlantis was the fourth operational shuttle built."
echo "--------------"
;;
enterprise)
echo "--------------"
echo "Space Shuttle Enterprise was the first Space Shuttle orbiter."
echo "--------------"
;;
pathfinder)
echo "--------------"
echo "Space Shuttle Orbiter Pathfinder is a Space Shuttle simulator made of steel and wood."
echo "--------------"
;;
*)
echo "Error: Please try again (select 1..7)!"
;;
esac
done但是,当我试图在jupyter笔记本上运行它时,它不起作用,我尝试了(我也尝试了代码本身):
%%bash
cd /shellfilepath
bash file.sh
cd /shellfilepath
bash file.sh | 1
%%bash
cd /shellfilepath
bash file.sh | echo "1"
%%bash
cd /shellfilepath
if bash file.sh; then echo "1"输出停止进入选择,假设为1,shell文件应该向我显示选择1的输出,我想要的是shell文件读取1作为一个条目。
发布于 2020-09-27 14:49:33
您的脚本从标准输入中读取。如果希望其他进程的输出成为脚本的标准输入,则需要使用管道。
$ echo 3 | bash file.sh
1) columbia 3) challenger 5) atlantis 7) pathfinder
2) endeavour 4) discovery 6) enterprise
Enter the space shuttle to get quick information : --------------
Space Shuttle Challenger was NASA's second Space Shuttle orbiter to be put into service.
--------------
Enter the space shuttle to get quick information :请注意,在这种情况下,您的脚本不知道输入来自文件,因此它仍然打印菜单等,就好像它正在与用户交互一样。
https://unix.stackexchange.com/questions/610145
复制相似问题