<分区>
我通过以下方式将用户名和密码传递给 jq:
json=$(jq -n --arg u "user_dev" --arg p "user!" '{username: $u, password: $p}')
但是,它失败并给出以下输出:
-bash: !": event not found
它似乎不喜欢 arg p "user!"的感叹号
<分区>
我通过以下方式将用户名和密码传递给 jq:
json=$(jq -n --arg u "user_dev" --arg p "user!" '{username: $u, password: $p}')
但是,它失败并给出以下输出:
-bash: !": event not found
它似乎不喜欢 arg p "user!"的感叹号
最佳答案
shell 将其解释为历史扩展。请改用单引号来防止这种情况。
json=$(jq -n --arg u "user_dev" --arg p 'user!' '{username: $u, password: $p}')
也就是说,bash
4.3 包含一个修复程序以防止这种情况发生。来自变更日志:
l. The history expansion character (!) does not cause history expansion when followed by the closing quote in a double-quoted string.
关于linux - jq 不使用感叹号作为输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43987641/