How to assign a glob expression to a variable in a Bash script?

后端 未结 8 1461
渐次进展
渐次进展 2020-12-08 02:21

When the following two lines of code are executed in a bash script, \"ls\" complains that the files don\'t exist:

dirs=/content/{dev01,dev02}
ls -l $dirs
         


        
8条回答
  •  抹茶落季
    2020-12-08 02:34

    Since you want to glob files, you shouldn't use brace expansions. Using brace expansion in this case is an antipattern and definitely the wrong tool for the job.

    What you want is extended globbing:

    shopt -s extglob # likely already set in interactive shells
    
    dirs=/content/@(dev01|dev02)
    ls $dirs
    

提交回复
热议问题