I'm able to use arguments if they are not surrounded by quotes:
var=$(jq -n --arg hostname "my-hostname" '{
Name: $hostname
}
)
echo $var
Result:
{
Name: "my-hostname"
}
But I want to concatenate the variable with an existing string, it ignores the value:
var=$(jq -n --arg hostname "my-hostname" '{
Name: "prefix-value-$hostname"
}
)
echo $var
Result:
{
Name: "prefix-value-"
}
Expected:
{
Name: "prefix-value-my-hostname"
}
Replace
"prefix-value-$hostname"
with
"prefix-value-\( $hostname )"
jqplay
or
"prefix-value-" + $hostname
jqplay
Note that since host names can't contain line feeds, -n
and --arg
could be replaced with -R
and stdin.
echo my-hostname | jq -R '{ Name: "prefix-value-\(.)" }'
jqplay
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With