I am new to bash scripts, I am trying to group multiple expressions in my if statement
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
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 ((...))
:
#!/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
minuteRun=50 HR=01
case $minuteRun:$HR in
50:01|50:13) echo ok;;
*:01|*:13 ) echo fail;;
esac
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.