好,我不能让这出于某种原因提前容易BASH的if else
if /etc/mysql/my.cfn exist
then goto end;
else bash install.sh;
end exit;;
谢谢, 乔
好,我不能让这出于某种原因提前容易BASH的if else
if /etc/mysql/my.cfn exist
then goto end;
else bash install.sh;
end exit;;
谢谢, 乔
这里有一个相对直译:
if [ -e /etc/mysql/my.cfn ]; then
exit # Note: bash does not have a goto command
else
bash install.sh
fi
或者,消除那么无关紧要的条件,和反转测试:
if [ ! -e /etc/mysql/my.cfn ]; then
bash install.sh
fi
检查不存在的,如果真正运行install.sh
。
[[ ! -e /etc/mysql/my.cfn ]] && bash install.sh
+1,喜欢简洁的形式,太... – 0xC0000022L 2011-04-02 19:50:48
+1的风格... – lecodesportif 2011-04-02 23:09:02
由于某种原因,即使文件中存在这种没有工作,仍然跑脚本。 – jmituzas 2011-04-02 23:57:26
(一)正确的语法是:
if [[ expression ]]; then
command
else
command
fi
传统的风格将是:
if test -f filename; then
command
fi
你四行猛砸的一行:
[[ -e /etc/mysql/my.cfn ]] && exit || bash install.sh
您是不是要找我。 CNF?
更少的代码只有更好,当你正在做的每行一两件事。 – Johnsyweb 2011-04-02 22:26:02
不完整'[[..]] && .. || ..测试结构按定义做至少两件事情?如果它简短易读,则可以在一行上完成。 – lecodesportif 2011-04-02 23:03:23
的确如此定义,这是我的一点做多件事情。它使代码难以维护。 – Johnsyweb 2011-04-03 03:10:07
在不带任何参数猛砸:
命令是一个空操作,所以你可以,如果你需要做什么使用在if体。
if something; then
:
else
do something else
fi
当然,你通常需要写为:
if ! something; then
do something else
fi
或
something || do something else
应该是'在/ etc/mysql /下my.cnf',我想。 – 0xC0000022L 2011-04-02 19:51:24