shell将多行文本重定向到文件【转】

在shell中,使用Here Document方式将文本重定向到文件,格式如下:

 

(
cat << EOF
要写的文本
EOF
) > 目标文件

 


示例test.sh:

 

#! /bin/sh
(
cat << EOF
{
    "warehouse":"$1",
    "ipaddr": "$2",
    "bindaddr": "$2:9995",
    "repopath": "./repo/",
        "kafka": "100.69.168.38:9095",
        "topic": "AgentHeartBeat",
        "partition": "1"
}
EOF
) >  agent/conf/agent.conf.json1

 

 

 

执行"test.sh ys 192.168.1.80"的结果:

[root@lvs00 monitor-agent]# cat agent/conf/agent.conf.json1
{
    "warehouse":"ys",
    "ipaddr": "192.168.1.80",
    "bindaddr": "192.168.1.80:9995",
    "repopath": "./repo/",
        "kafka": "192.168.1.2:9095",
        "topic": "AgentHeartBeat",
        "partition": "1"
}
[root@lvs00 monitor-agent]#

 

转自

shell将多行文本重定向到文件 - dingtao7890的博客 - CSDN博客
http://blog.csdn.net/dingtao7890/article/details/53523706

 
posted @ 2017-10-10 14:09  paul_hch  阅读(684)  评论(0编辑  收藏  举报