Ubuntu的B Shell

Ubuntu的B Shell是一个指向dash shell的符号链接,因此要注意Bash的扩展变量展开会失败。如果将shebang行设为#!/bin/sh,则会发生“Bad substitution”错误。

$ cat /etc/os-release
NAME="Ubuntu"
VERSION="16.04.3 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.3 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial
$ export LANG=C
$ which sh
/bin/sh
$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 May 11 14:15 /bin/sh -> dash
$ ls -l /bin/dash
-rwxr-xr-x 1 root root 154072 Feb 18  2016 /bin/dash
$ dash
$ echo $SHELL
/bin/bash
$ test='ABCDEFG'
$ echo $test
ABCDEFG
$ echo ${test:2:3}    # Bashの拡張変数展開に失敗; Bashならば CDE と表示
dash: 12: Bad substitution

当尝试将文本文件加载到数组中时,也会出现错误。

$ cat sports.sh
#!/bin/sh
sports=(`cat sports.txt`)
for sport in ${sports[@]}
do
  echo $sport
done
exit
$ ./sports.sh
./sports.sh: 2: ./sports.sh: Syntax error: "(" unexpected
$ /bin/bash sports.sh
soccer
baseball
...
广告
将在 10 秒后关闭
bannerAds