vinWin
vinWin

Reputation: 603

Printing value of variable with echo -e option

Echo when used with -e option doesn't seem to output/expand value of a variable

Using this way as it's been part of framing json file

Tried with backtick to expand variable value. And also with (( to eval as expression

echo -e '"compVersion:","$compLatestVer",' >> framed.json

eg : with compLatestVer=2.3.4 When I echo it, it just prints

echo -e '"compVersion:","$compLatestVer",'

to file rather than expanded value

I tried with

echo -e '"compVersion:","`$compLatestVer`",'

Also with

echo -e '"compVersion:","((compLatestVer))",'

without luch

echo -e '"compVersion:","2.3.4",'

Upvotes: 0

Views: 262

Answers (1)

chepner
chepner

Reputation: 531045

Don't use echo. Use printf instead.

printf '"compVersion": "%s"' "$compLatestVer"

However, building up a JSON value piecemeal like this is also wrong; use a tool like jq to generate it for you.

(I adjusted the format string, since it looks like you are trying to output key/value pairs for a JSON object.)

Upvotes: 1

Related Questions