美文网首页
运行shell脚本报错syntax error: unexpec

运行shell脚本报错syntax error: unexpec

作者: 浩瀚之宇 | 来源:发表于2019-04-19 10:19 被阅读0次
$cat test.sh 
#!/bin/sh
function show() {
    echo "hello , world"
}
show
$ sh test.sh 
test.sh: 2: test.sh: Syntax error: "(" unexpected

查看shell版本

$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 May  1  2018 /bin/sh -> dash

因为Ubuntu/Debian为了加快开机速度,用dash代替了传统的bash,解决方法就是

sudo dpkg-reconfigure dash

Removing 'diversion of /bin/sh to /bin/sh.distrib by dash'
Adding 'diversion of /bin/sh to /bin/sh.distrib by bash'
Removing 'diversion of /usr/share/man/man1/sh.1.gz to /usr/share/man/man1/sh.distrib.1.gz by dash'
Adding 'diversion of /usr/share/man/man1/sh.1.gz to /usr/share/man/man1/sh.distrib.1.gz by bash'

相关文章

网友评论

      本文标题:运行shell脚本报错syntax error: unexpec

      本文链接:https://www.haomeiwen.com/subject/wzofgqtx.html