我直接复制你这个,直接运行,没有任何报错啊。
[flycat@redhat script]$ sh -x aaa.sh
+ PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/home/flycat/bin
+ export PATH
+ echo 'Input your selection'
Input your selection
+ case $1 in
+ echo 'Usage {one|two|three}'
Usage {one|two|three}
[flycat@redhat script]$ chmod 755 aaa.sh
[flycat@redhat script]$ ./aaa.sh
Input your selection
Usage {one|two|three}
[flycat@redhat script]$ ./aaa.sh one
Input your selection
Your choice is ONE
[flycat@redhat script]$ ./aaa.sh two
Input your selection
Your choice is TWO
[flycat@redhat script]$ ./aaa.sh three
Input your selection
Your choice is THREE
的确没错啊,会不会是编辑器的问题?
以前我用windows记事本存了个脚本,怎么改都运行错误,转utf8什么都没用,最后发现记事本存的gb2312转utf8开头多几个字符...
代码完全没有问题,在我这里可以执行.
不过你的程序中既然提示"input your selection",应该使用read来即时获得输入,而不是使用$1这样的位置变量。当然这取决于你自己,并不影响程序执行。
shell脚本第9行中有个括号“(”语法不对,建议你贴出来看看
chmod +x sh11-2.sh
加权限了吗?