tags:

views:

83

answers:

3

i have a script like that

genhash --use-ssl -s $IP -p 443 --url $URL | grep MD5 | grep -c $MD5

i want to get stream generated by genhash in a variable, how do i redirect it into a variable $hash to compare inside a conditional

if [ $hash -ne 0 ]
  then echo KO
  exit 0
else echo -n OK
  exit 0
fi
+2  A: 

Use the $( ... ) construct:

hash=$(genhash --use-ssl -s $IP -p 443 --url $URL | grep MD5 | grep -c $MD5)
anon
+1 for amazingly rapid response
markcial
A: 

You can do:

hash=$(genhash --use-ssl -s $IP -p 443 --url $URL)

or

hash=`genhash --use-ssl -s $IP -p 443 --url $URL`

If you want to result of the entire pipe to be assigned to the variable, you can use the entire pipeline in the above assignments.

codaddict
A: 

I guess compatible way:

hash=`genhash --use-ssl -s $IP -p 443 --url $URL | grep MD5 | grep -c $MD5`

but I prefer

hash="$(genhash --use-ssl -s $IP -p 443 --url $URL | grep MD5 | grep -c $MD5)"
ony