linux - jq 不使用感叹号作为输入

标签 linux bash shell sh jq

我通过以下方式将用户名和密码传递给 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/

相关文章:

c++ - cpp : eclipse doesn't recognize 'long long' type

docker - 在 .bashrc 中导出 DOCKER_HOST 对终端中的相同命令产生不同的结果

sql - Linux脚本问题

file - 用于删除名称在文本文件中的文件的 Shell 命令/脚本

linux - 如何将 telnet 控制台日志重定向到文件 Linux

linux - 监控多个 Linux 系统或服务器脚本

c++ - gcc 函数属性 - 如何使用它们?

c++ - psmouse 驱动反鼠标

linux - 无密码 ssh 有效但不适用于 Hadoop

c++ - 使用QT读取socket