我有一个Ubuntu机设置来砸默认的shell和$ PATH两种方式二进制:为什么bash的行为不同,当它被称为sh?
$ which bash
/bin/bash
$ which sh
/bin/sh
$ ll /bin/sh
lrwxrwxrwx 1 root root 4 Mar 6 2013 /bin/sh -> bash*
但是,当我尝试调用使用the inline file descriptor(仅Bash可以处理,但没有一个脚本SH)两个调用不同的表现:
$ . ./inline-pipe
reached
$ bash ./inline-pipe
reached
$ sh ./inline-pipe
./inline-pipe: line 6: syntax error near unexpected token `<'
./inline-pipe: line 6: `done < <(echo "reached")'
示例脚本我指的是看起来像
#!/bin/sh
while read line; do
if [[ "$line" == "reached" ]]; then echo "reached"; fi
done < <(echo "reached")
现实一个是一点点长:
#!/bin/sh
declare -A elements
while read line
do
for ele in $(echo $line | grep -o "[a-z]*:[^ ]*")
do
id=$(echo $ele | cut -d ":" -f 1)
elements["$id"]=$(echo $ele | cut -d ":" -f 2)
done
done < <(adb devices -l)
echo ${elements[*]}
用shebang(#!/ ...)看到实际的脚本 - 特别是引导线会很有帮助。其次,你现在用哪个“$”提示符运行哪个shell? – Daniel
SRY,我认为这很清楚。它运行在默认shell(按照我的第一句话)bash。也会上传脚本。 – fragmentedreality
http://www.gnu.org/software/bash/manual/bashref.html#Bash-POSIX-Mode –