In a bash script, how can I say 'for all files of type .png or .PNG'?
I'm trying :
for i in (`ls *.PNG` && `ls *.png`)
but getting a syntax error.
|
In a bash script, how can I say 'for all files of type .png or .PNG'? I'm trying :
but getting a syntax error. |
||||
|
|
|
You could also try some one-liner such as
or
Edit |
|||||
|
|
Notes:
|
|||
|
|
|
If you want all possible combinations, use:
or
although that one will make all of your script's shell globs (i.e. wildcard file matches) case insensitive until you run If you really want just .PNG and .png (and not, for example, .PnG or .pnG), then use either
or
...the reason for the nullglob or existence check is that if you have only lowercase or only uppercase extensions, it'll include the unmatched pattern in the list of files, leading to an error in the body of the loop. As with nocaseglob, you might want to turn the nullglob shell option off afterward (although in my experience having nullglob on is often good, especially in a script). Actually, I rather consider it a good idea to use either the nocaseglob or existence check for all file matches like this, just in case there are no matches. |
|||||||
|