user1467267
user1467267

Reputation:

Wildcard within quotations

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?

Upvotes: 2

Views: 967

Answers (3)

Andreas Louv
Andreas Louv

Reputation: 47127

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"

Upvotes: 3

sjsam
sjsam

Reputation: 21965

No globbing is done inside double quotes. Do

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

See this [ question ] for some detail.

Upvotes: 4

riteshtch
riteshtch

Reputation: 8769

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

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

Upvotes: 5

Related Questions