Trying to read fifo in bash. why do I get error?
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"
The error I get:
./sh.sh: line 12: [: missing `]' ./sh.sh: line 14: [HelloWorld: command not found
When running from other shell and print HelloWorld
You are missing a command for the
ifstatement, and you needspaces in the
elifstatement.should be
A slightly cleaner option, if you don’t mind bashisms: