exit的差异:
方法一:
#!/bin/bash
echo -e "1\n2\n3" > /tmp/testfile
function abc(){
cat /tmp/testfile | while read line;do
echo $line
exit
done
}
echo Starttttttttt
abc
echo Enddddddddddd
方法二:
#!/bin/bash
echo -e "1\n2\n3" > /tmp/testfile
function abc(){
while read line;do
echo $line
exit
done<<<"$(cat /tmp/testfile)"
}
echo Starttttttttt
abc
echo Enddddddddddd
方法一结果:
Starttttttttt 1 Enddddddddddd
方法二结果:
Starttttttttt 1
可以看出方法一中的exit无法退出脚本
© 著作权归作者所有
文章评论(0)