rm fails to delete files by wildcard from a script, but works from a shell prompt

前端 未结 6 614
广开言路
广开言路 2021-01-30 19:51

I\'ve run into a really silly problem with a Linux shell script. I want to delete all files with the extension \".bz2\" in a directory. In the script I call

rm \         


        
6条回答
  •  时光取名叫无心
    2021-01-30 20:43

    Your original line

    rm "$archivedir/*.bz2"
    

    Can be re-written as

    rm "$archivedir"/*.bz2
    

    to achieve the same effect. The wildcard expansion is not taking place properly in your existing setup. By shifting the double-quote to the "front" of the file path (which is legitimate) you avoid this.

提交回复
热议问题