因此,我试图使用交互式脚本来选择一系列文件。
最终目标是使用read命令,但为了演示,我手动分配了glob变量
#!/bin/bash
shopt -s extglob
# read -rp "Please enter a globbing string:"错误如下:Error /bin/ls: cannot access "/mnt/drive1/images/*/*/*2020_04_03_{06..18}.jpg": No such file or directory那么,在分配glob变量或将glob变量附加到我的路径时,这里遗漏了什么呢?解决方案:我找到了解决办法,但我不太清楚为什么bash <会给我想要的输出。\n' glob
# This will give me an error (See below)
glob=*2020_04_03_{06..18}.jpg
/bin/ls -la /mnt/drive1/images/*/*/${glob}
# While this will return the desired files
/bin/ls -la /mnt/drive1/images/*/*/*2020_04_03_{06..18}.jpg错误如下:
A3
那么,在分配D4变量或将D5变量附加到我的路径时,这里遗漏了什么呢?
解决方案:
我找到了解决办法,但我不太清楚为什么
A6
会给我想要的输出。
发布于 2020-04-06 00:36:12
您可以使用数组赋值,而不仅仅是变量。
shopt -s nullglob ##: just in case there is non match for the glob.
glob=(*2020_04_03_{06..18}.jpg) ##: This will expand the glob * and brace expansion.
/bin/ls -la /mnt/drive1/images/*/*/"${glob[@]}"failglob shell选项,如果没有匹配模式,则退出非零。https://unix.stackexchange.com/questions/578133
复制相似问题