我试图在FOR循环中使用IF/ELSE语句生成两个输出文件:数字为1-5的count1;数字为6-10的count2
我在努力
for i in {1..10}
do
if [ $i -le 5 ]
then
echo $i > count1.out
else
echo $i > count2.out
fi
done
但count1中只有"5“,而count2则显示"10”
我怎么才能解决这个问题?
发布于 2016-02-25 03:28:49
您正在使用截断-重定向运算符>
。
您可能打算使用附加-重定向运算符>>
。
一般考虑阅读BASh I/O重定向。 --它将极大地帮助您理解shell脚本。
发布于 2016-02-25 03:28:18
使用>
重定向到文件将替换文件的全部内容。您实际上想要做的是将其附加到文件中,您可以使用>>
这样做:
echo "hello " > somefile.out # replace the contents of whatever is in somefile.out
echo "world!" >> somefile.out # append more stuff to somefile.out
更多信息在这里:node/Redirections.html
https://stackoverflow.com/questions/35617637
复制相似问题