2012-07-30 38 views
0

試圖閱讀bash中的fifo。爲什麼我會得到錯誤?爲什麼在閱讀shell中的fifo時出現錯誤?

pipe="./$1" 

trap "rm -f $pipe" EXIT 

if [[ ! -p $pipe ]]; then 
    mkfifo $pipe 
fi 

while true 
do 
    if read line <$pipe; then 
      if "$line" == 'exit' || "$line" == 'EXIT' ; then 
       break  
      elif ["$line" == 'yes']; then 
       echo "YES" 
      else 
       echo $line 
      fi 
    fi 
done 

echo "Reader exiting" 

的錯誤,我得到:

./sh.sh: line 12: [: missing `]' ./sh.sh: line 14: [HelloWorld: command not found 

其他外殼和打印HelloWorld

+2

你什麼錯誤? – chepner 2012-07-30 13:33:30

回答

2

你們是if語句中缺少一個命令運行時,你需要在elif聲明 空間。

if "$line" == 'exit' || "$line" == 'EXIT' ; then 
    break  
elif ["$line" == 'yes']; then 

應該

if [ "$line" = 'exit' ] || [ "$line" = 'EXIT' ] ; then 
    break  
elif [ "$line" = 'yes' ]; then 

稍微清潔劑的選擇,如果你不介意bash化:

if [[ $line = exit || $line = EXIT ]]; then 
    break 
elif [[ $line = yes ]]; then 
相關問題