问题
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