shell 如何将路径列表从变量传递到GNU updatedb的选项

9o685dep  于 2023-05-01  发布在  Shell
关注(0)|答案(1)|浏览(100)

我想通过macOS上的GNU updatedb在shell脚本中更新locatedb
最后的命令调用如下所示:

updatedb --localpaths='/' --prunepaths='/System /Volumes/MyFirstVol /Volumes/MySecondOne /Volumes/NumeroThree'

但是,卷/Volumes/MyFirstVol/Volumes/MySecondOne/Volumes/NumeroThree I在shell $PRUNEVOLS变量中以空格分隔:

$ echo $PRUNEVOLS
/Volumes/MyFirstVol /Volumes/MySecondOne /Volumes/NumeroThree

(Side注:我用线

PRUNEVOLS=$(echo $(ls -1d /Volumes/* | grep -v /Volumes/IndexMe))

初始化$PRUNEVOLS。)
我的问题是:如何在updatedb调用中使用$PRUNEVOLS?
我在shell scrpt中尝试了各种调用::

  • updatedb --localpaths='/' --prunepaths='/System $PRUNEVOLS'-这不起作用,因为$PRUNEVOLS未扩展
  • updatedb --localpaths='/' "--prunepaths='/System $PRUNEVOLS'"-这里$PRUNEVOLS被展开了,但是它仍然不工作。
i34xakig

i34xakig1#

从第一个示例(未使用变量)中,我们可以看到--prunepaths不希望在其参数中使用单引号。因此,A

updatedb --localpaths=/ "--prunepaths=/System $PRUNEVOLS" -

应该可以

相关问题