BASH Wildcard Expansion
Posted
by
Aaron Copley
on Server Fault
See other posts from Server Fault
or by Aaron Copley
Published on 2011-01-11T22:29:38Z
Indexed on
2011/01/11
22:55 UTC
Read the original article
Hit count: 392
I'm not really sure how to phrase this, and maybe that's why I can't find any thing, but I want to reuse the values enumerated by a wildcard in a command. Is this possible?
Scenario:
$ ls /dir
Contents of /dir are directories 1, 2, and 3.
1 2 3
$ cp /dir/*/file .
Results in file being copied from /dir/1 /dir/2 and /dir/3 to here.
What I would like to do is copy the files to a new destination name based on the wildcard expansion.
$ cp /dir/*/file ???-file
Would result in /dir/*/file being copied to 1-file, 2-file, and 3-file. What I can't figured out is the ???
portion to tell BASH I want to use the wildcard expanded values.
Using the wildcard in the target nets a cp error: cp: target `*-file' is not a directory. Is there something else in bash that can be used here?
The find command has {}
to use with -exec
which is similar to what I am looking for above.
© Server Fault or respective owner