linux shell脚本 总报错sh11-2.sh: 9: Syntax error: "(" unexpected

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux shell脚本 总报错sh11-2.sh: 9: Syntax error: "(" unexpected相关的知识,希望对你有一定的参考价值。

程序如下所示
但是第九行的 ( 没有问题啊。改了好多次都不对。
#!/bin/bash
# Program :
# This program is to input one two three and then show it in screen
# Histroy :
# 2011/10/31 Alan
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

function printit()
echo -n "Your choice is "


echo "Input your selection"
case $1 in
"one")
printit ; echo $1 | tr 'a-z' 'A-Z'
;;
"two")
printit ; echo $1 | tr 'a-z' 'A-Z'
;;
"three")
printit ; echo $1 | tr 'a-z' 'A-Z'
;;
*)
echo "Usage one|two|three"
;;
esac

这个括号有什么问题呢?谢谢。

我直接复制你这个,直接运行,没有任何报错啊。

[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追问

额,那我这儿怎么会出现这问题呢。。。

追答

echo $SHELL

看看你的shell

追问

是/bin/bash

参考技术A 的确没错啊,会不会是编辑器的问题?
以前我用windows记事本存了个脚本,怎么改都运行错误,转utf8什么都没用,最后发现记事本存的gb2312转utf8开头多几个字符...
参考技术B 代码完全没有问题,在我这里可以执行.
不过你的程序中既然提示"input your selection",应该使用read来即时获得输入,而不是使用$1这样的位置变量。当然这取决于你自己,并不影响程序执行。
参考技术C shell脚本第9行中有个括号“(”语法不对,建议你贴出来看看 参考技术D chmod +x sh11-2.sh
加权限了吗?

shell脚本安装pythonpip--不需要选择安装项目

shell脚本安装python、pip--不需要选择安装项目--不管用总报错,必须带上判断符号,while没有这种用法,写在这里为了以后少走弯路,
所以不要用下面的执行了


首先把pip-18.0.tar.gz 、Python-3.6.5.tgz 安装包放在 /usr/local 下面,按照顺序先安装pip,再安装python。不要先安装或只安装python,否则很容易出错, #!/bin/bash func1(){ while true do echo "安装依赖包" yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel echo "安装pip" yum remove pip -y && cd /usr/local/ && tar -xf pip-18.0.tar.gz && cd pip-18.0/ && python setup.py install echo "安装python" cd /usr/local/ && tar -zxvf Python-3.6.5.tgz && mv Python-3.6.5 python3 && cd python3 && ./configure && make && make install mv /usr/bin/python /usr/bin/python.bak ln -s /usr/local/bin/python3 /usr/bin/python && ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3 whereis pip && /usr/local/bin/pip3.6 install --upgrade pip && /usr/local/bin/pip install paramiko sed -i "1c #!/usr/bin/python2.7" /usr/bin/yum sed -i "1c #!/usr/bin/python2.7" /usr/libexec/urlgrabber-ext-down sed -i "1c #!/usr/bin/python2.7" /usr/sbin/firewalld echo "全部安装完毕" exit done } func1

 





以上是关于linux shell脚本 总报错sh11-2.sh: 9: Syntax error: "(" unexpected的主要内容,如果未能解决你的问题,请参考以下文章

shell脚本报错

shell脚本空行造成“: not found.sh“报错的解决方法(unix与windows文本格式切换)

shell脚本执行source报错

Windows编写shell脚本,Linux运行不起来,报错

Windows编写shell脚本,Linux运行不起来,报错

linux arm 运行 shell .sh 脚本文件报错:/bin/bash^M: bad interpreter: No such file or directory(dos2unix )(代码片