我有一個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 –