$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為了加快開機(jī)速度,用dash代替了傳統(tǒng)的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'