Home > OS >  sh not found on shell
sh not found on shell

Time:12-24

I am facing with a while loop executing inside shell. Below is the script and error :

while [ $(curl -s http://<servicename>:<portnumber>/hazelcast/health | jq '.clusterSize') -ne $(size_1) ];do 
  sleep 2
  echo 'Waiting for the `bjy-hazelcast'
done

Output :

sh: 3: not found

CodePudding user response:

Try this :

Assuming size_1 is a command, if not change "$(size_1)" to "$size_1"

while [ "$(curl -s http://<servicename>:<portnumber>/hazelcast/health | jq '.clusterSize')" -ne "$(size_1)" ]
    do 
        sleep 2
        echo 'Waiting for the `bjy-hazelcast'
    done

CodePudding user response:

$(...) is a process substitution, and the text inside is interpreted as a command. It would seem that $size_1 is expanding to the string 3, and the shell is attempting to execute 3 as a command and complaining that it cannot find such a command. You should omit the $() and just do:

"$(curl ...)" -ne "$size_1"
  • Related