我已经完成了一项任务,即让某个程序显示menu
类似的用户界面,并执行简单的任务,例如ls
who
和top
然后进行shell脚本分叉到子进程,然后从新创建的子进程运行后续命令。但我不懂C ++,而是想使用Shell脚本。我到目前为止的代码如下:
#!/bin/bash
trap '' 2 #trapping the CTRL + C command so users are forced to use number 4 to stop.
while true #while statement for the return function
do
clear #clears the screen so it doesn't look messy when looping
echo "=============================================="
echo "| Outside The CPU Shell Script |"
echo "=============================================="
echo "| Enter 1 for Who |"
echo "| Enter 2 for Ls |" #basic echos to show the menu
echo "| Enter 3 for Top |"
echo "| Enter 4 to exit |"
echo "=============================================="
echo -e "\n" #returns a new line
echo -e "Enter your selection \c |" #prompts to select while suppressing output
read answer #reads input and stores value in variable named answer
case "$answer" in # a case statement (like if/elif statement) using variable answer
1) who ;; #actual command that is used
2) ls ;;
3) top ;;
4) exit ;;
esac #ending statement for the case
echo -e "Enter return to continue \c" #the return statement to bring back to main menu
read input #read enter and store in variable input
done
如何在此脚本调用fork时进行处理,然后控制它创建的子进程?
谢谢,