I am trying to pass a variable into jq like this '.Linux.date.$var'
so far I have tried quoting them by name which is working fine. But I want to use variable to call them.
I have this, which is working fine
exectime=$(date -d now);
cp $check_exec_history $check_exec_history.tmp
jq --arg key1 true --arg key2 "$exectime" --arg name "$name" '.Linux.script_executed.first = $key1 | .Linux.date_executed.first = $key2' $check_exec_history.tmp > $check_exec_history;
rm $check_exec_history.tmp;
I want to get to this, but not working:
name=first;
exectime=$(date -d now);
cp $check_exec_history $check_exec_history.tmp
jq --arg key1 true --arg key2 "$exectime" --arg name "$name" ".Linux.script_executed.$name = $key1 | .Linux.date_executed.$name = $key2" $check_exec_history.tmp > $check_exec_history;
rm $check_exec_history.tmp;
I came this far: using this answer https://stackoverflow.com/q/40027395/9496100 But I am not sure where I am doing mistake.
name=first;
exectime=$(date -d now);
cp $check_exec_history $check_exec_history.tmp
jq --arg key1 true --arg key2 "$exectime" --arg name "$name" '.Linux.script_executed.name==$name = $key1 | .Linux.date_executed.name==$name = $key2' $check_exec_history.tmp > $check_exec_history; rm $check_exec_history.tmp;