Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 582

Why my string comparison isn't working in bash?

$
0
0

I've a script that does something like this:

set -xmyJson="echo '{\"data\":\"true\"}'"commandOutput=$(eval $myJson | jq '.data')echo $commandOutputwhile :do    if [[ $commandOutput == "true" ]]    then        break    fi    sleep 1doneecho "Done"

However, my string comparison never works. The only way I managed this to work was putting '"true"' in the string comparison. It seems that is something related to the eval. Since I've set the x flag here is the output of this script:

+ myJson='echo '\''{"data":"true"}'\'''++ eval echo ''\''{"data":"true"}'\'''+++ echo '{"data":"true"}'++ jq .data+ commandOutput='"true"'+ echo '"true"'"true"+ :+ [[ "true" == \t\r\u\e ]]+ sleep 1+ :+ [[ "true" == \t\r\u\e ]]+ sleep 1+ :+ [[ "true" == \t\r\u\e ]]+ sleep 1

It seems that the string at the right side is being always scaped, if this is the case why is this happening?


Viewing all articles
Browse latest Browse all 582

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>