jq not working with exclamation mark as an input [duplicate]

拟墨画扇 提交于 2019-12-12 06:22:02

问题


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

It seem that it is not liking exclamation mark with the arg p "user!"


回答1:


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}')

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

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



来源:https://stackoverflow.com/questions/43987641/jq-not-working-with-exclamation-mark-as-an-input

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!