0

bash で 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

4

1 に答える 1

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

バシズムを気にしないのであれば、少しクリーンなオプション:

if [[ $line = exit || $line = EXIT ]]; then
    break
elif [[ $line = yes ]]; then
于 2012-07-30T13:40:37.000 に答える