[英]Bash script multiple if express groups
I am new to bash scripts, I am trying to group multiple expressions in my if statement我是 bash 脚本的新手,我正在尝试在 if 语句中对多个表达式进行分组
minuteRun = $1
if
[
[ [ $minuteRun -eq 25 ] && [ $HR != 01] && [ $HR != 13 ] ] ||
[ [ $minuteRun -eq 50 ] && [ $HR -eq 01 || $HR -eq 13 ] ]
]
then
I call it as ./script.sh 45
我称之为
./script.sh 45
Here are the errors这是错误
There are syntax errors esp.有语法错误,尤其是。 space between brackets eg
[ [
括号之间的空格,例如
[ [
It is better to use arithmetic context in bash for this using ((...))
:为此,最好在 bash 中使用算术上下文
((...))
:
#!/usr/bin/env bash
minuteRun=$1
if
((
( minuteRun == 25 && HR != 1 && HR != 13 )
||
( minuteRun == 50 && ( HR == 1 || HR == 13 ) )
))
then
Personally i'd use case
for this我个人会为此使用
case
minuteRun=50 HR=01
case $minuteRun:$HR in
50:01|50:13) echo ok;;
*:01|*:13 ) echo fail;;
esac
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.