Is there any way in bash to glob files that does not end with a certain suffix ?
e.g. I'm doing this:
mv $INCDIR/HDR_10_* $BACKUPDIR
But I don't want to move the HDR_10_* that ends with .gz
|
feedback
|
|
This would work for the file move:
You also asked 'to glob files that does not end with a certain suffix ?'
Bash has the shell option (shopt) extglob, which allows extended globbing syntax. The
would work only if $INCDIR contained only files named HDR_10_*, specifically it would match any file or directory in $INCDIR that doesn't match *.gz. Technically you're asking for a glob that both matches one pattern but not another, which i don't think exists as a simple single entity. | |||||||||
feedback
|
|
Under ksh, One solution, in any Bourne-style shell (ash, bash, ksh, zsh, ...), is to iterate over the files and check each match.
Another solution is to use
If you have GNU find (e.g. under Linux), You can add Note that You should always use double quotes around variable substitutions (e.g. | |||
|
feedback
|
|
If you use I am sure there are better constructions, but this is one that comes to mind right away:
A correction was pointed-out in the comments that the above quick-stab won't work because of
| |||||||||||
feedback
|