【发布时间】:2017-09-27 16:41:41
【问题描述】:
*已编辑以更新状态
我正在尝试制作一个 bash 文件,该文件将允许您选择一个选项、输出答案,然后返回到菜单选择。截至目前,我的代码是:
#!/bin/sh
echo off
echo "........................................."
echo "Select the process you would like to run."
echo.
echo "1 - Free Disk Space Available"
echo "2 - List Directories"
echo "3 - Show Running Processes"
echo "4 - TCP Connection"
echo "5 - Network Interfaces"
echo "6 - List Directories"
echo "7 - Show Computer Hostname"
echo "8 - Routing Table"
echo "9 - Computer Uptime"
echo "10 - Available Block Devices"
echo "11 - Mount Device"
echo "........................................."
echo -n "Input desired function number and press ENTER: "
read selection
while [ {selection} ]
do
if [ $selection == 1 ]; then echo df -h
break
elif [ $selection == 2 ]; then echo ls -l /home
break
elif [ $selection == 3 ]; then echo ps -A
break
elif [ $selection == 4 ]; then echo netstat -a
break
elif [ $selection == 5 ]; then echo ifconfig
break
elif [ $selection == 6 ]; then echo $PATH
break
elif [ $selection == 7 ]; then echo hostname
break
elif [ $selection == 8 ]; then echo route
break
elif [ $selection == 9 ]; then echo uptime
break
elif [ $selection == 10 ]; then echo blkid
break
elif [ $selection == 11 ]; then echo mount
break
else
echo "Please enter a valid option"
fi
done
我得到的输出是一个无限循环的错误
[: 2: 意外操作符
如果有人可以帮助我或指导我正确的方向,我将不胜感激。
【问题讨论】:
-
那个编辑完全改变了这个问题。可以更新问题,但请考虑在对您有帮助的答案中添加评论,说明您遇到了另一个问题。
-
请注意,
echo off打印出单词“off”。 bash 不是批处理。
标签: linux bash loops while-loop menu