Bash 数字范围的case语句
我正在写剧本Bash 数字范围的case语句,bash,case,Bash,Case,我正在写剧本 case "${x_time}" in 10) cp fileA fileB ;; 20) cp fileC fileD ;; *) echo "Please check the $x_time" ;; esac 我想要1..10而不是10和11..20而不是20。e、 g.(1 | 2 | 3 |…| 10)我的意思是,如果$x|u时间是7,则应执行第一个块,对于18,第二个块对于21,则执行*) 有没有检查$x_time列表的解
case "${x_time}" in
10) cp fileA fileB
;;
20) cp fileC fileD
;;
*) echo "Please check the $x_time"
;;
esac
我想要1..10
而不是10
和11..20
而不是20
。e、 g.(1 | 2 | 3 |…| 10)
我的意思是,如果$x|u时间是7
,则应执行第一个块
,对于18,第二个块
对于21,则执行*)
有没有检查$x_time
列表的解决方案?
谢谢 改用
[[]]
测试:
if [[ $x_time -ge 1 && $x_time -le 10 ]]; then
cp fileA fileB
elif [[ $x_time -ge 11 && $x_time -le 20 ]]; then
cp fileC fileD
else
echo "Please check the $x_time"
fi
也可以根据您的喜好使用(())
if (( x_time >= 1 && x_time <= 10 )); then
cp fileA fileB
elif (( x_time >= 11 && x_time <= 20 )); then
cp fileC fileD
else
echo "Please check the $x_time"
fi
if((x_time>=1&&x_time=11&&x_time)我实际使用了if…fi
,但我正在寻找类似的倍数或,以防万一。无论如何,谢谢。