我想知道爲什麼即使使用明確的退出命令,該腳本仍會繼續運行。Bash退出不退出
我有兩個文件:
file1.txt
具有以下內容:
aaaaaa bbbbbb cccccc dddddd eeeeee ffffff gggggg
file2.txt
具有以下內容:
111111 aaaaaa 222222 333333 ffffff 444444
腳本(test.sh
)是這樣的,兩個嵌套循環檢查第一個文件的任何行是否包含第二個文件的任何行。如果發現匹配,則中止。
#!/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
我得到的,即使它應該打印第一!!!!!!!!!!
後退出以下的輸出:
aaaaaa !!!!!!!!!! bbbbbb cccccc dddddd eeeeee ffffff !!!!!!!!!! gggggg
是不是exit
應該徹底終結腳本的執行?
我能想到的唯一原因是由於管道進入'while'。管道將爲'while'啓動另一個子進程(shell),因此'while'內的'exit'會退出該shell並返回到原始文件。 – lurker