不影响UNIX中shell脚本的错误行
/菜单:第12行:[1:未找到命令 即使不影响脚本的功能,这个东西也会不断出现 脚本:不影响UNIX中shell脚本的错误行,shell,unix,Shell,Unix,/菜单:第12行:[1:未找到命令 即使不影响脚本的功能,这个东西也会不断出现 脚本: #!/bin/bash/usr/lib/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/rvs130@studin.aubgin.$ function press_enter { echo "" echo -n
#!/bin/bash/usr/lib/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/rvs130@studin.aubgin.$
function press_enter
{
echo ""
echo -n "Press Enter to continue"
read
clear
}
choice=
until ["$choice" = "0"]; do
echo ''
echo ' SMILEY SERVER MENU'
echo '1 - To view the available smilies'
echo '2 - Search for a smiley'
echo '3 - Add a new smiley'
echo '4 - Delete a smiley'
echo '5 - Edit smiley or description'
echo ''
echo '0 - Exit'
echo 'Enter your choice: '
read choice
case "$choice" in
1)
cat smilies.txt;;
2)
echo 'Please enter the name of the smiley you want to see: '
read name
echo 'Match found: '
grep $name smilies.txt ;;
3)
echo 'Enter the smiley you want to add followed'
echo 'by a space and description: '
read newsmiley
echo "$newsmiley" >> smilies.txt
echo 'New smiley added.' ;;
4)
echo 'Enter a smiley or its description you want to delete: '
read delsmiley
sed -i /"$delsmiley"/d smilies.txt ;;
5)
echo 'Enter a word you want to edit, space'
echo 'and then desired replacement word: '
read word1 word2
replace "$word1" "$word2" -- smilies.txt ;;
0) exit ;;
*)
echo 'Please enter a valid choice.'; press_enter
esac
done
必须在
[
和]
周围有空格。脚本中发生的情况是,第一轮$choice
为空,因此行的计算结果为[=“0”]
,这将导致类似于bash:[:missing`]
第一轮的错误(除非您设置-o errexit
,否则这不会影响执行)。选择1并再次返回测试行后,它的计算结果为[1=“0”]
,其中[1
被解释为您要运行的命令。您需要的是:
until [ "$choice" -eq 0 ]
另外,这是无效的。我可能会更改此选项:直到[“$choice”=“0”];执行”