在 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
?
不需要eval
- 只是e1=$(< ./deploy/request.json)
应该可以解决问题。 (感谢@shellter的语法 - 你甚至不需要使用cat
!
要显示变量,您需要
echo "$e1"
而不仅仅是"$e1"
."$e1"
本身在命令行上不会打印出$e1
的值,不像许多编程语言的REPL那样。 相反,它告诉 bash 尝试将$e1
的全部内容解释为命令的名称。 它不是命令的名称,因此 bash 告诉您找不到该名称的命令。