Assigning output from awk to variable Assigning output from awk to variable shell shell

Assigning output from awk to variable


Use command substitution to assign the output of a command to a variable.

The syntax is: var1=$(command).

result=$(awk 'BEGIN{s=100} END {print s}' /dev/null)echo "The result is $result"


The awk command needs to have some input!

awk 's=100 END  {print  s }' <input file here>

you need to change your line to:

result= `awk 's=100 END  {print  s }' <input file>`

the reason why it hangs is that awk is wating for its input!