0

I have a file which extract the price of a product. But when I compare the price with another value, the comparison does not go true.

The following is the code

        price= cat temp.html | sed 's/,/\n/g'  | grep -m 1 "selling_price" | sed 's/:/\n/g' | tail -n1;
        target=15
        echo $price
        if [[ $price -gt $target ]];  then
        echo $url;
        exit
        fi

But if I change the extraction price with specific price then it goes true.

        price=16
        target=15
        echo $price
        if [[ $price -gt $target ]];  then
        echo $url;
        exit
        fi
habib
  • 1
  • 1
  • 2
    You're not actually storing the command output in the variable; see ["How do I set a variable to the output of a command in Bash?"](https://stackoverflow.com/questions/4651437/how-do-i-set-a-variable-to-the-output-of-a-command-in-bash) Also, you should (almost) always double-quote variable references, e.g. `echo "$url"` instead of just `echo $url`. – Gordon Davisson Mar 27 '23 at 02:32
  • http://shellcheck.net/ is your friend. – Charles Duffy Mar 27 '23 at 02:37

0 Answers0