linux shell写入单行、多行内容到文件

1、单行文本

#! /bin/bash
echo 'hello world' > filename.txt

2、多行文本

代码1:


#! /bin/bash
cat>filename.txt<<EOF
hello world
代码改变世界 Coding Changes the World
100 \$
她买了张彩票,中了3,300多万美元。
She bought a lottery ticket and won more than\$ 33 million.
EOF

 

代码2:

 

#! /bin/bash
filename="/test/filename.txt"
cat>"${filename}"<<EOF
hello world
代码改变世界 Coding Changes the World
100 \$
她买了张彩票,中了3,300多万美元。
She bought a lottery ticket and won more than\$ 33 million.
EOF

 

说明:
1.其中,<<EOF 表示当遇到EOF时结束输入。
2.cat>test1.txt<<EOF 这间没有空格
3.$号要加\转义字符

相关文章

系ubuntu 下面打开终端输入:sudo apt-get install sendmail...
依家我有1个软件goagent目录(大家懂得) 放在/home/gateman/...
其实我想讲的是 cp -L关于-L参数的解释:-L, --dereferenc...
原地址:http://www.rjgc.net/control/content/content.php?...
chroot,即 change root directory (更改 root 目录)。在 li...
简单解析下, stdin就是标准输入, stdout就是标准。举个例子...