2

When I do the following:

rmdir /path/to/dir/*.lproj

it works fine.

When I do:

APP_RESOURCES="/path/to/dir"
rmdir "$APP_RESOURCES/*.lproj"

It doesn't work and says it literally looks for a directory named with an astrix-symbol. The wildcard doesn't get interpreted. How can this be made to work within quotations?

oguz ismail
  • 1
  • 16
  • 47
  • 69

3 Answers3

5

Expansion is handled by the shell so you will have to write something like this:

APP_RESOURCES="/path/to/dir"
rmdir "${APP_RESOURCES}/"*.lproj
riteshtch
  • 8,629
  • 4
  • 25
  • 38
4

No globbing is done inside double quotes. Do

APP_RESOURCES="/path/to/dir"
rmdir "$APP_RESOURCES"/*.lproj

See this [ question ] for some detail.

Community
  • 1
  • 1
sjsam
  • 21,411
  • 5
  • 55
  • 102
3

You are quoting your variable expansions, keep doing that. Bad thing is that you try to quote your globbing. For the shell to glob you shouldn't quote:

app_resource="/path/to/dir"
rmdir "$app_resource"/*.lproj

This will however still expand to /path/to/dir/*.lproj in cases where no match is found, consider this:

% app_resource="/path/to/dir"
% echo "$app_resource/something/that/doesnt/exists/"*.abc
/path/to/dir/something/that/doesnt/exists/*.abc

One way around that is to check if the file/directory exists:

app_resource="/path/to/dir"
dir_to_remove="$app_resource/"*.lproj
[ -d "$dir_to_remove" ] && rmdir "$dir_to_remove"
Andreas Louv
  • 46,145
  • 13
  • 104
  • 123