Help with BASH command to variable

Soldato
Joined
6 Jan 2013
Posts
21,927
Location
Rollergirl
Been throwing everything at this, but just can't get it to play nice. I'm trying to extract info from an api.

If I have :

Code:
echo "$jsonTxt" | jq '.[0].algo' | sed "s/\"//g"

It outputs :

Code:
x15

That output is perfect, it's the first algo returned. I want that "x15" into a variable so I can use it later in the script, so I'm trying :

Code:
outputTxt=$("$jsonTxt" | jq '.[0].algo' | sed "s/\"//g")
echo "$outputTxt"

But it errors, saying :

Code:
line 16: "[{"algo":"x15","score":"0.00443727"},{"algo":"x13","score":"0.0031609"},{"algo":"x11","score":"0.00192839"},{"algo":"nscrypt","score":"0.0014518"},{"algo":"scrypt","score":"0.000689165"},{"algo":"nist5","score":"0"}]": command not found
 
Associate
Joined
20 Aug 2010
Posts
1,099
Location
Not Coventry
Code:
echo "$jsonTxt" | jq '.[0].algo' | sed "s/\"//g"
The first command here is to print the contents of $jsonTxt using echo, this is then piped into the following commands.

Code:
outputTxt=$("$jsonTxt" | jq '.[0].algo' | sed "s/\"//g")
echo "$outputTxt"
Here you are not printing the contents of $jsonTxt, but rather trying to run the contents as a command.
 
Back
Top Bottom