david
david

Reputation: 6805

How to use exit code as conditional in simple 2 line bash script

url="http://localhost:8080/matlib"
until $(curl "$url" --max-time 10) == 0; do stuck_pid=$(chown_pid); kill -9 $stuck_pid && "killing chmod process";done

what I'm trying to do is curl this address, if it times out after 10 seconds, then term a PID.

The part that is failing is the '== 0', the intention here was to compare the return code from curl with 0, but I'm receiving the following error:

-bash: ==: command not found

Upvotes: 0

Views: 46

Answers (1)

anubhava
anubhava

Reputation: 785991

This indeed is the problem:

$(curl "$url" --max-time 10) == 0

== operator must be inside [[ ... ]] or [ ... ] square brackets.

However you are not comparing exit status of curl but output of curl since you are executing $(...) or command substitution.

You should be using just:

until curl "$url" --max-time 10; do ...; done

Upvotes: 1

Related Questions