json - 我如何在回声中添加引号?
问题描述
我需要一些帮助。我正在尝试做这样的事情
echo "{
"server":"$SERVER_HOST",
"server_port":"$SERVER_PORT",
"password":"$PASSWORD_CHOICE",
"timeout":$TIMEOUT_CHOICE
}" >> /etc/ss/example.json
我需要像这样的输出
{
"server":"127.0.0.1",
"server_port":80,
"password":"randompassword",
"timeout":60
}
但输出总是像
{
server:127.0.0.1,
server_port:80,
password:randompassword,
timeout:60
}
解决方案
不要使用echo
,而是cat
使用此处的文档:
cat >> /etc/ss/example.json <<EOF
{
"server":"$SERVER_HOST",
"server_port":"$SERVER_PORT",
"password":"$PASSWORD_CHOICE",
"timeout":$TIMEOUT_CHOICE
}
EOF
推荐阅读
- bash - 几秒钟后在while循环内停止“dd”
- bash - 在 docker 中更新环境变量
- c++ - 析构函数和向量
- recursion - Clojure:如何检查输入是否只有一个序列长?
- sql - 如何从连接的表中删除重复项?
- scala - EMR Spark - libcrypto.so.1.0.0 的链接不满意
- javascript - 为什么 Express.js 重定向在 Node.js MongoDB 应用程序中抛出错误 [ERR_HTTP_HEADERS_SENT]?
- python - 我如何从网站上抓取隐藏的数据
- sql - 查找 EId 和 EName
- c++ - 1String 将自身附加到另一个 C++ 的末尾