Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash Wildcard use

Tags:

bash

I am trying to remove files in a directory using rm and without deleting the directory itself in a script. The examples I see only do this while in the directory itself, and I would like to do it without navigating there.

I tried

rm "$(dirname $1)/filetokeep/*"

but it is not working. Any help?

like image 908
user2805565 Avatar asked Sep 23 '13 02:09

user2805565


1 Answers

Quoting the wildcard inhibits expansion.

rm -- "$(dirname -- "$1")/filetokeep"/*

Using -- ensures that values can't be interpreted as optional arguments rather than positional ones (so that things still work if the directory named in $1 starts with a -).

like image 52
Ignacio Vazquez-Abrams Avatar answered Oct 05 '22 23:10

Ignacio Vazquez-Abrams