您的位置:首页 > 运维架构 > Shell

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

2017-10-10 14:09 260 查看
在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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: