基本for循环:
$for i in $(seq 1 5); do echo $i; done 1 2 3 4 5
$(seq 1 5):这是在另一个子shell中执行命令。
$seq 1 5 1 2 3 4 5
当我们想要启动新子shell 时,可以使用$()
语法。
bash shell遍历文件示例:
$for i in $(ls *.txt); do cat "$i" | head -n1; done 1 1 1 1 1
$for i in $(ls *.txt 2>/dev/null); do echo -n "$(tail -n1 $i)"; echo " from $i !" ; done 1 from 1.txt ! 2 from 2.txt ! 3 from 3.txt ! 4 from 4.txt ! 5 from 5.txt !
日期:2020-07-07 20:54:29 来源:oir作者:oir