Hi I am trying to build a program in bash. The idea is that I would have open two terminals. One would take the input with a pipe
cat > pipe
while true; do
if [ "$input" == "exit" ]; then
Your second script should be something like :
#!/bin/bash pipe="$1" # Here $1 is full path to the file pipe as you have confirmed while true do input=$(cat<"$pipe") if [[ $input =~ exit ]] #original line was if [ "$input" == "exit" ] then exit 0 fi done
$(cat<"$pipe") will store the entire file as a string. So, even though you have the word
exit somewhere down in the
pipe file the original condition
if [ "$input" == "exit" ] will be false except the case when the first word you enter for
cat>pipe itself is "exit".
A little tweakish solution is do a regex match
(=~) as I have done but this solution is not very reliable because if you enter something like "I don't wanna exit", for
cat>pipe the second script will exit.
A second solution would be :
#!/bin/bash pipe="$1" while true; do input=$(tail -n1 "$pipe") #checking only the last line if [[ "$input" == "exit" ]] #original if condition then exit 0 fi done