处理循环的输出
#!/bin/bash
# shell脚本中,可以对循环的输出使用管道或进行重定向。
# 可以通过在done命令之后添加一个处理命令来实现。
for (( a=1; a<10; a++ ))
do
echo "the number is $a"
done > test.txt
echo "the command is finished"
echo "********** 循环结果传输到另一个命令 ***********"
# piping a loop to another command
# 输出的结果都是排序后的。
for state in "North Dakota" Connecticut Illinois Alabama Tennessee
do
echo "$state is the next place to go"
done | sort
运行结果:
ll查看,生成新文件“test.txt”
cat test.txt