Linux: Red Hat Enterprise Linux Server release 6.5 (Santiago)
BASH: GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
One of the VM that I just provisioned is still waiting for the DNS to update it's node entries and one the node has a NAS which is mounted on at /project_support
folder. It takes around 5-10 minutes for /project_support
folder to be accessible, yea bad I know.
For my automation not break due to this issue and I didn't want to add a constant sleep NNN
, I used until
loop so that until the mount is mounted and /project_support
folder is available, I wanted to sleep for 5 seconds and check for folder existence before proceeding further in the automation script/logic.
Why the first until
loop is continuing and not exiting on the condition check when cd
command to a given folder is successful aka exit status 0
? The second until is working as expected.
For the 2nd until loop, even if I create the folder (from a second terminal, while until loop is running), it still doesn't break the until loop.
[root@nukaserver01 ~]# cd /project_support; echo $?
0
[root@nukaserver01 project_support]# pwd
/project_support
[root@nukaserver01 project_support]# until [ `cd /project_support` ]; do echo '-- sleep 5'; sleep 5; done
-- sleep 5
-- sleep 5
-- sleep 5
^C
[root@nukaserver01 project_support]# until [ `cd /project_support-I-DONT-EXIST-AT-ALL` ]; do echo '-- sleep 5'; sleep 5; done
-bash: cd: /project_support-I-DONT-EXIST-AT-ALL: No such file or directory
-- sleep 5
-bash: cd: /project_support-I-DONT-EXIST-AT-ALL: No such file or directory
-- sleep 5
^C
[root@nukaserver01 project_support]#
Why is this issue getting fixed when I do: ?
until [ `cd /project_support && pwd` ]; do ...; ...; done