0

I have a very-long-oneliner that outputs true or false whose I want to wait to be true to process further. My until loop works OK this way:

var=$(very-long|oneliner)
until [[ $var = true ]]; do sleep 5
var=$(very-long|oneliner); done

But when I want get it lighter:

var=$(very-long|oneliner)
until [[ $var = true ]]; do sleep 5
var=$var; done

it fails when initial $var is false because var after do is never updated as I hoped. I learned this is because at some point the loop goes in a sub shell, then var is no more the output of the oneliner, but get stuck to false. Is there a way to do it ? Maybe the first line would be declare -g var=$(very-long|oneliner) (I never used this and am afraid it spreads I don't know where in the system),or declare -x var=$(very-long|oneliner)?

Thanks in advance for hints.

1 Answer 1

1

Simplify. Make sure your one-liner exits with a valid code.

until very-long|oneliner
do sleep 5
done

as long as very-long|oneliner returns 0 then true, it'll work.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Paul, but I don't understand: the end of the oneliner is awk that searches a specific line in a file and ouputs the last word, false or true, then it always exits with 0. Even when I drive it where it won't find true or false... OK, I got it work this way, with the help of grep to get a reliable 0|1 exit code. I wasn't able with awk only + 1 week reading the excellent gawk manual : until [[ `$verylongcurl/command.org|awk -v DID=$DevID '$0~DID,/}/ {if ($0~/online/) print}'|grep "\"online\": true,"` ]]; do sleep 5; done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.