Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assigning output from awk to variable

Tags:

shell

unix

aix

awk

I have a script whose contents are as below:

    result= awk 's=100 END  {print  s }' 
    echo "The result is" $result

The desired output is:

The result is 100

My script is running without exiting and I am also not getting the desired output. Please help.

like image 369
user1929905 Avatar asked Dec 27 '12 10:12

user1929905


1 Answers

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"
like image 167
dogbane Avatar answered Sep 19 '22 22:09

dogbane