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

linux shell写入单行、多行内容到文件的更多相关文章

  1. Linux Shell 05 位置变量(命令行参数)

    在Linux shell 脚本中可能会用到一些命令行参数,常见如下: $0:脚本名称 $#:执行脚本时传入的参数个数,不包括脚本名称 $@:所有参数 $*:所有参数 $1...$9:第1个参数.... ...

  2. linux 查看某几行内容与文件分割

    查看指定行数 sed -n 4,8p file #打印file中的4-8行 sed -n 4p file #打印file中的第4行 grep ^pw file # 查看file中以pw开头的行 在Li ...

  3. linux shell脚本查找重复行/查找非重复行/去除重复行/重复行统计

    转自:http://blog.sina.com.cn/s/blog_6797a6700101pdm7.html 去除重复行 sort file |uniq 查找非重复行 sort file |uniq ...

  4. 【Linux Shell】uname命令行

    常用命令uname -v # uname -i #uname -a dream361@master:~$ uname -n #主机名称 master dream361@master:~$ uname ...

  5. linux shell的单行多行注释

    1.单行注释,使用符号# echo " echo "test" #echo "comment“ 2. 多行注释 (1)使用 :<<!  ! file ...

  6. linux shell脚本连接oracle查询数据插入文件和日志文件中

    #!/bin/sh sqlplus "用户名/密码@数据库"<<EOF  或者只有一个库的 :sqlplus "用户名/密码"<<EOF ...

  7. Linux系统通过AWS命令行上传文件至S3

    打开你的AWS控制台: 在IAM中创建一个新用户(比如test),创建时它会自动创建一个用户安全凭证,是由“访问密钥ID”和“私有访问密钥”组成的,请记住它并下载该凭证,后面会用到它: 选择你刚创建的 ...

  8. cat输出多行内容到文件

    输出格式是: cat > f1.sh <<end ...... end ----------------- == cat < f1.sh ## 同一行中的顺序可以改变 .... ...

  9. Linux shell unzip和tar 批量解压文件

    #!/bin/sh UNTAR="tar -xvf " #unzip all zip files function unzip_all_file() { for i in *.zi ...

随机推荐

  1. leetcode56:合并区间

    给出一个区间的集合,请合并所有重叠的区间.(解题思想来源于:https://blog.csdn.net/qq_34364995/article/details/80788049 ) 示例 1: 输入: ...

  2. day 20 collection模块 time 模块 os 模块

    一.collection模块 1.namedtuple: 生成可以使用名字来访问元素内容的tuple 2.deque: 双端队列,可以快速的从另外一侧追加和推出对象 3.Counter: 计数器,主要 ...

  3. jetty调优

    jetty服务器使用遇到一下内存溢出的问题: java.lang.OutOfMemoryError: unable to create new native thread   无法创建新的进程 方法: ...

  4. 继承and派生

    1.什么是继承?(python2与python3) 在程序中继承是一种新建子类的方式,新创建的类称之为子类\派生类,被继承 的类称之为父类\基类\超类 继承描述的是一种遗传关系,儿子可以重用爹的属性 ...

  5. Oracle自我补充之OVER()函数介绍

    OVER(PARTITION BY)函数介绍 开窗函数               Oracle从8.1.6开始提供分析函数,分析函数用于计算基于组的某种聚合值,它和聚合函数的不同之处是:对于每个组返 ...

  6. npm http-server ubuntu

    Node.js中http-server的使用 使用阿里的npm镜像 国外的npm太慢了.查看一下自己使用的源: npm config get registry 1 应该显示https://regist ...

  7. help2man: can't get `--help' info from automake-1.15 Try `--no-discard-stderr' if option outputs to stderr Makefile:3687: recipe for target 'doc/automake-1.15.1' failed

    /********************************************************************** * help2man: can't get `--hel ...

  8. 【leetcode】7-ReverseInteger

    problem: Reverse Integer 注意考虑是否越界: INT_MAX INT_MIN 32bits or 64bits 调整策略,先从简单的问题开始:

  9. markdown-to-html.min.js

    直接改成  false 不执行这里 不然异步了

  10. Nginx反向代理与Backend直接配置长连接

    使用了Nginx的反向代理配置如下: upstream test{ keepalive 1; server 192.168.1.63:4000; } server { listen 4000; ser ...