加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-15 07:06:13 所属栏目:安全 来源:网络整理
导读:1、单行文本 #! /bin/bash echo 'hello world' filename.txt 2、多行文本 代码1: #! /bin/bash catfilename.txtEOF hello world 代码改变世界 Coding Changes the World 100 $ 她买了张彩票,中了3,300多万美元。 She bought a lottery ticket and won mor

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.$号要加转义字符

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读