在bash shell中,我尝试读取json文件并加载到一个变量
eri@xyz:~/Documents/inbound>e1=$(eval echo $(cat ./deploy/request.json))在获取该变量的输出时,我看到了-bash - command not found以及.json文件的实际内容
eri@xyz:~/Documents/inbound>"$e1"
-bash: { type:Pipeline, category:Software, risk:4, short_description:sample short description text, description:sample detailed description text, assignment_group: Services - Retail Services, cmdb_ci:Retail Service, u_version:1.0, start_date:2017-01-04 18:00:00, end_date:2017-01-04 19:00:00, backout_plan:see department for standard backout plan, implementation_plan:sample implementation plan, test_plan:sample text plan, production_system:false }: command not found有没有办法抑制输出中的-bash - command not found?
发布于 2018-08-10 10:05:08
不需要eval --只要用e1=$(< ./deploy/request.json)就行了。(感谢@shellter提供的语法- you don't even need to use cat!)
要显示变量,您需要
echo "$e1"而不仅仅是"$e1"。与许多编程语言"$e1"不同,命令行上的REPL本身不会输出$e1的值。相反,它告诉bash尝试将$e1的全部内容解释为命令的名称。它不是命令的名称,所以bash会告诉您无法找到具有该名称的命令。
https://stackoverflow.com/questions/51777888
复制相似问题