ls with numeric range doesn't work inside bash script

后端 未结 4 549
星月不相逢
星月不相逢 2020-12-21 07:03

I have a folder with files named as file_1.ext...file_90.ext. I can list a range of them with the following command:

$ ls /home/rasoul/myfolder/         


        
4条回答
  •  太阳男子
    2020-12-21 07:14

    The range pattern {A..B} does not accept variables for A or B. You need constants for them. A workaround might be to start a subshell like this:

    RESULT=$(bash -c "ls {$a..$b}")
    

提交回复
热议问题