I am trying to insert the output below into the variable x. The output is a string. I have done this before.
k="psz"
And when I do this it works and i get the expected output when doing echo $x
x=$( awk -v a="k" -F '[:,]' '{ if($1 == "psz") print $5 }' /etc/passwd )
But when i try to use this one below it doesn't work
x=$( awk -v a="k" -F '[:,]' '{ if($1 == a) print $5 }' /etc/passwd )
It does not work, echo $x gives me a blank line.
kisn't defined beforeif($1 == k), you meanif($1 == "k")? orif($1 == a)?if ($1 == a)notk, and if you wantato be set with the value ofk, then you should pass-v a=$kinstead.-va=kinstead of-va=$k, the right form.