在bash中的while循环的布尔类型? [英] boolean type for while loop in bash?
本文介绍了在bash中的while循环的布尔类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在共享的网络主机上有一个cron脚本,偶尔会被杀死。我想在bash中再次尝试一个循环,如果它被杀死,因为大多数时间,它会使它。我在存储布尔值的语法时遇到问题:P
I have a cron script on a shared web host that occasionally gets killed. I'd like to make a loop in bash that tries again if it gets killed, because most of the time it will make it. I'm having trouble with the syntax for storing a boolean value :P
#!/bin/bash
VAR=0;
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=1;
fi
done
所以脚本从kill进程恢复正常,但是一旦正常运行,新的 VAR
值不会杀死,而
循环。
So the script recovers from a killed process okay, but once it's run properly, the new VAR
value doesn't kill the while
loop.
我做错了什么?
推荐答案
尝试
while [ $VAR -eq 0 ]; do
0
和 1
都被视为True,因为它们不是空字符串。
0
and 1
are both considered True because they are not null strings.
这篇关于在bash中的while循环的布尔类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文