【发布时间】:2019-06-10 05:24:39
【问题描述】:
我想将一个变量写入 JSON 文件。
我尝试了许多 sed 命令,但仍然找不到解决方案
#! bin/bash
echo "Hello"
echo "lets create an instance"
read -p "please enter the type of instance you need: " instance_type
echo $instance_type | sed -i "s|""InstanceType"": """"|""InstanceType"":
""${instance_type}""|g" awsspotinstancecreation.json
roxor@ubuntu:~$ bash rough.sh
Hello
lets create an instance
please enter the type of instance you need: t2.small
{
"ImageId": "ami-074acc26872f26463",
"KeyName": "Accesskeypair",
"SecurityGroupIds": ["sg-064caf9c470e4e8e6"],
**##"InstanceType": "${instance_type}",##**
"Placement": {
"AvailabilityZone": "us-east-1a"
}
}
【问题讨论】:
-
您好,请提供minimal reproducible example。这意味着样本 json 输入和样本所需的 json 输出。第三,它现在做了什么(所以失败的 JSON 结果)。另请查看 StackOverflow 的帮助页面,并了解如何使用编辑器来格式化您的问题。照原样,它是不可读的。