You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to use jo in a shell script by appending key value-pairs to a variable, and passing this as an argument to jo, but I'm not getting the expected output:
jo_script.sh:
#!/bin/bash
value0="foo"
value1="bar"
value2="foo bar"
string="'key0=${value0}' 'key1=${value1}' 'key2=${value2}'"
# Contents of string: 'key0=foo' 'key1=bar' 'key2=foo bar'
jo "$string"
Output:
{"'key0":"foo' 'key1=bar' 'key2=foo bar'"}
Expected output:
{"key0":"foo","key1":"bar","key2":"foo bar"}
Any ideas why this is happening?
The text was updated successfully, but these errors were encountered:
In short, jo "$string" stopped word-splitting from happening, because you quoted $string. Removing the double quotes doesn't work either, because your key2 value has a internal space which would also be split.
What you're trying to do (build a list of arguments for a command) is such a common task that there's a bash idiom for it: Use arrays. Specifically:
I'm trying to use jo in a shell script by appending key value-pairs to a variable, and passing this as an argument to jo, but I'm not getting the expected output:
jo_script.sh:
Output:
Expected output:
Any ideas why this is happening?
The text was updated successfully, but these errors were encountered: