boolean type for while loop in bash?
No need to you a helper variable, consider using:
while ! mysqldump .....; do :;done
Try
while [ "$VAR" -eq 0 ]; do
0
and 1
are both considered True because they are not null strings.
You could use /bin/true
and /bin/false
. Although while ! mysqldump .....; do :;done
(Jürgen Hötzel's solution) would be better in this case, there are other cases when using true
and false
are useful.
#!/bin/bash
VAR=true
while $VAR; do
if nice -19 mysqldump -uuser -ppassword -h database.hostname.com --skip-opt --all --complete-insert --add-drop-table database_name > ~/file/system/path/filename.sql; then
VAR=false
fi
done