jq不能使用感叹号作为输入 [英] jq not working with exclamation mark as an input

查看:75
本文介绍了jq不能使用感叹号作为输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过以下方式将用户名和密码传递给jq:

I am passing username and password to jq the following way:

json=$(jq -n --arg u "user_dev" --arg p "user!" '{username: $u, password: $p}')

但是,它失败了,并给出以下输出:

However, it is failing and giving the following output:

-bash: !": event not found

似乎不喜欢arg p "user!"

推荐答案

shell将其解释为历史扩展.改用单引号防止出现这种情况.

The shell is interpreting it as a history expansion. Use single quotes instead to prevent that.

json=$(jq -n --arg u "user_dev" --arg p 'user!' '{username: $u, password: $p}')

也就是说,bash 4.3包含一个修复程序,可以防止这种情况的发生.从变更日志中:

That said, bash 4.3 includes a fix to prevent that from happening. From the changelog:

l.历史扩展字符(!)在以下情况下不会引起历史扩展 然后在双引号字符串中加上右引号.

l. The history expansion character (!) does not cause history expansion when followed by the closing quote in a double-quoted string.

这篇关于jq不能使用感叹号作为输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆