运行shell脚本报错syntax error: unexpec

2019-04-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'

上一篇 下一篇

猜你喜欢

热点阅读