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

后端 未结 8 1457
渐次进展
渐次进展 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:56

    The issue which no-one has addressed is that the variable assignment makes the difference.

    dirs=/content/{dev01,dev02}
    

    expands differently than

    echo /content/{dev01,dev02}
    

    The question is how to assign the results of the expansion to dirs

    See: How to use Bash substitution in a variable declaration

提交回复
热议问题