我目前正在学习BASH脚本,我对IF / WHILE / UNTIL循环语句有疑问。我正在尝试了解哪一个更有效地检查文本语句的变量内容,如果没有找到我可以使用until
语句来检查变量吗?示例用法是这样的(我用它来检查系统是否更新,如果没有,它会更新):
#!/bin/bash
# Flush the YUM cache since we've added new directories and repo's
flushcache=$(yum clean all);
# Does our system need to be updated?
checkupdate=$(yum update | grep -i "No Packages marked for Update");
# This will update the system
updatesystem=$(yum update -y);
# Flush the YUM cache, to make sure we get the newest package list
echo "$flushcache";
# Using a LOOP (until-logic), lets make sure we're all updated!
if [[ $checkupdate != "No packages marked for update" ]]
then
echo "$updatesystem"
else
echo "They system is already updated";
fi
exit 0;
脚本通常存在,所以这很好,但我想知道我是否以最有效的方式实现我的新学习。此外,这将循环直到$checkupdate
是一个真实的陈述?我很想听听一些专业的意见!
任何帮助仍然有帮助!谢谢你放纵我!