0

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!"

stack4rme
  • 105
  • 1
  • 2
  • 5
  • Efforts to build a [mcve] presumably would have lead to a discovery that this is reproducible without `jq` involved at all. – Charles Duffy May 15 '17 at 20:05

1 Answers1

3

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.

chepner
  • 497,756
  • 71
  • 530
  • 681