What does !< means in this bash script, and why it points to file that does not exist?
bash -c 'while !</dev/tcp/db/5432; do sleep 1; done; npm start'
Thanks in advance for your time!
! is a negation operator.
Example:
while ! false; do
echo "inside while loop"
sleep 1
done
will be inside the loop forever since ! false is always true.
< is another operator. It tells bash to read the specified file. It will succeed (return zero exit code) if file exists and is readable. Without left operand, the read results will be discarded.
Example: check for /tmp/sample_file existence:
if < /tmp/sample_file; then echo 'file exists'; fi
Thus, your code will run sleep 1 in a loop while /dev/tcp/db/5432 cannot be read.
Now take into account that /dev/tcp/ is a special path and accessing /dev/tcp/db/5432 means trying to connect to host db via TCP port 5432.
So the logic behind your while loop is 'sleep until postgresql on host db is ready' (5432 is the default port for PostgreSQL).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With