linux - 评估变量 - 输出 json 文件内容
问题描述
在 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"
. 与许多编程语言 REPL 不同"$e1"
,命令行本身不会打印出 的值。$e1
相反,它告诉 bash 尝试将 的全部内容解释$e1
为命令的名称。它不是命令的名称,因此 bash 会告诉您找不到该名称的命令。
推荐阅读
- python - 有没有办法使用 selenium 或其他方式与 Discord 屏幕共享权限弹出窗口交互
- json - 如何使用 jmeter 从 json 断言中识别特定的真或假值?
- sql - 如果必须分块处理数据,从sql将数据加载到redis中会更好吗?
- android - 在 Android 10 或更高版本中从后台服务启动 Activity
- c++ - 如何使用 C++ 覆盖二进制文件的一部分?
- awk - 使用列数据打印列的 awk 命令
- google-chrome - Chromium 源代码树中的“站点设置”在哪里?
- javascript - 如何在 ReactJS 中使用事件监听器?
- javascript - 出口清单 Fullcalendar en pdf
- ajax - Ajax 请求被禁止 - 错误 403 - strict-origin-when-cross-origin