-1

I've coded this script:

for i in `seq 1 $1`; do
        timestamp=$(uuidgen)
        cat $2.json | jq '.transactionId = "$timestamp"' > $3/$timestamp.json
done

My issue is on jq '.transactionId = "$timestamp"' since the content of file is:

{
  "transactionId": "$timestamp"
}

Any ideas?

Micha Wiedenmann
  • 18,825
  • 20
  • 87
  • 132
Jordi
  • 18,082
  • 29
  • 125
  • 263
  • You mentioned you have an issue with a particular line. Could you tell us what the issue is and why it is an issue? – kvantour Jan 08 '19 at 13:46
  • 2
    Just change single quotes for double quotes: `jq "... '$timestamp'"` – F. Hauri Jan 08 '19 at 13:54
  • As an aide, avoid the [useless `cat`](/questions/11710552/useless-use-of-cat) and [quote all your variables.](/questions/10067266/when-to-wrap-quotes-around-a-shell-variable) – tripleee Jan 09 '19 at 05:09

1 Answers1

6

There are better ways to pass variables to jq:

$ cat data.test
{
  "foo": "noooo"
}
$ new=bar
$ jq --arg new_foo "$new" '.foo |= $new_foo' data.test
{
  "foo": "bar"
}
Aserre
  • 4,641
  • 4
  • 32
  • 53
mickp
  • 1,559
  • 5
  • 18