-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
  • 19,979
  • 21
  • 92
  • 137
Jordi
  • 20,868
  • 39
  • 149
  • 333

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,916
  • 5
  • 33
  • 56
mickp
  • 1,679
  • 7
  • 23