1、单行文本
#! /bin/bash
echo 'hello world' > filename.txt
2、多行文本
代码1:
#! /bin/bash
cat>filename.txt<
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}"<
hello world
代码改变世界 Coding Changes the World
100 \$
她买了张彩票,中了3,300多万美元。
She bought a lottery ticket and won more than\$ 33 million.
EOF
说明:
1.其中,<
2.cat>test1.txt<
3.$号要加\转义字符