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. SpringMVC学习二

    处理请求 今天学了三种请求,一种是 PathVariable ,一种是 RequestParam ,还有一种是CookieValue,并实现简单rest增删改查 上代码 package com.spr ...

  2. 八、启动linux内核并修改开机logo

    1. 编译并烧写linux内核 1)先准备好内核源码包urbetter-linux2.6.28-v1.0.tgz,输入命令:tar -zxvf urbetter-linux2.6.28-v1.0.tg ...

  3. Linux:http配置

    http配置 1.挂载系统:mount /dev/cdrom /mnt/cdrom2.安装:rpm -ivh httpd-2.4.6-88.el7.centos.x86_64.rpm2.启动服务:sy ...

  4. python 3.x 字典的11种方法

    python 3.x 字典的11种方法2017年11月25日 01:02:11 Milton-Long 阅读数:535 标签: python python字典方法 更多个人分类: python-学习之 ...

  5. LeetCode--219、268、283、414、448 Array(Easy)

    219. Contains Duplicate II Given an array of integers and an integer k, find out whether there are t ...

  6. 机器学习: 共轭梯度算法(PCG)

    今天介绍数值计算和优化方法中非常有效的一种数值解法,共轭梯度法.我们知道,在解大型线性方程组的时候,很少会有一步到位的精确解析解,一般都需要通过迭代来进行逼近,而 PCG 就是这样一种迭代逼近算法. ...

  7. linux修改ssh端口 以及禁止root远程登录 (实验机 CentOs)

    把ssh默认远程连接端口修改为3333 1.编辑防火墙配置: vi /etc/sysconfig/iptables 防火墙新增端口3333,方法如下: -A INPUT -m state --stat ...

  8. js 关于本地文件的处理

    https://developer.mozilla.org/zh-CN/docs/Web/API/File/Using_files_from_web_applications

  9. linux lamp编译环境安装

    apache 安装:http://blog.csdn.net/wplblog/article/details/52172128 编译安装 mysql安装:http://www.centoscn.com ...

  10. nginx的安装 、Nginx默认虚拟主机、nginx用户认证、nginx 域名重定向

    1.nginx:官网:www.nginx.org 下载:wget -c  http://nginx.org/download/nginx-1.14.0.tar.gz解压:tar -zxvf nginx ...