2012-07-30 33 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 
相关问题