Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 数字范围的case语句_Bash_Case - Fatal编程技术网

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
,但我正在寻找类似的倍数
,以防万一。无论如何,谢谢。