I wonder why this script continues to run even with an explicit exit command.
I have two files:
file1.txt with the following content:
aaaaaa bbbbbb cccccc dddddd eeeeee ffffff gggggg
file2.txt with the following content:
111111 aaaaaa 222222 333333 ffffff 444444
The script (test.sh) is this, two nested loops checking if any line of the first file contains any line of the second file. If it finds a match, it aborts.
#!/bin/bash
path=`dirname $0`
cat $path/file1.txt | while read line
do
echo $line
cat $RUTA/file2.txt | while read another
do
if [ ! -z "`echo $line | grep -i $another`" ]; then
echo "!!!!!!!!!!"
exit 0
fi
done
done
I get the following output even when it should exit after printing the first !!!!!!!!!!:
aaaaaa !!!!!!!!!! bbbbbb cccccc dddddd eeeeee ffffff !!!!!!!!!! gggggg
Isn't exit supposed to end the execution of the script altogether?
while. The pipe will kick off another subprocess (shell) for thewhile, so theexitwithin thewhileexits that shell and your back to your original.