我有一个简单的shell脚本来选择diff任务并执行它。 如果选择了选项1,它将执行该任务并退出脚本。
但是我希望脚本等待用户输入另一个任务并执行它直到用户手动退出。
首先说用户选择选项1并获得输出。接下来,用户想要选择选项2并且应该获得输出。直到他手动退出脚本。
#!/bin/sh
echo "For Fruits [1] "
echo "For Vegetables [2] "
echo "For drinks [3] "
read output
case $output in
1)
cat 1.txt | tr , '\n' | sort >epackP.txt
cat 2.txt | tr " " '\n'| /usr/xpg4/bin/awk -F "T000" '{print $2}'|/usr/xpg4/bin/awk -F "+" '{print $1}'|sed '/^$/d' | sort >symmP.txt
diff -ibw 1.txt 2.txt
if [ $? -eq 0 ]; then
echo "********** Files matched :D **********"
else
echo "********** Mismatch found :( **********"
fi
;;
2)
cat 3.txt | tr , '\n' | sort >epackP.txt
cat 4.txt | tr " " '\n'| /usr/xpg4/bin/awk -F "T00" '{print $2}'|/usr/xpg4/bin/awk -F "+" '{print $1}'|sed '/^$/d' | sort >symmP.txt
diff -ibw 3.txt 4.txt
if [ $? -eq 0 ]; then
echo "********** Files matched :D **********"
else
echo "********** Mismatch found :( **********"
fi
;;
3)
diff -ibw 5.txt 6.txt
if [ $? -eq 0 ]; then
echo "********** Files matched :D **********"
else
echo "********** Mismatch found :( **********"
fi
;;
*)
echo "retry"
esac
答案 0 :(得分:0)
while true; do
read output
case $output in
1) ...
2)
3) break
esac
done
详细类似示例:Bash-Begginers-Guide