shell脚本中的读文件(while read line)与写文件(here document)

shell脚本中如何读取外部文件并进行相关操作呢?范式如下,是要背滴:

while read line;
do
    process $line
done < file

如何在写中将内容写入新文件呢,要用到here document,一种特殊的重定向技术,小范式如下,也是要牢记在心的:

cat << EOF > output.txt
echo "hello"
echo "world"
EOF

这时我们得到了output.txt文件里面的内容是

echo "hello"
echo "world"

猜你喜欢

转载自blog.csdn.net/BobChill/article/details/84333813