steviefordi
December 2nd, 2009, 09:49 PM
I've been writing a reasonably complex bash script for housekeeping. It reads a config file and based upon what it finds builds a number of calls to the find command.
One of the settings in the config file is a space delimited list of file masks, which I want to build into find command like so:
\ ( -iname 'mask1*.txt' -o 'mask2.???' -o '[0-9]mask3.old' \ )
As the for loop works through a space delimited list I thought it would be perfect, however bash understandably wants to glob all my masks before running through them. Quoting just breaks the output, so I've fixed it by turning off globbing:
set -f
For mask in $masklist; do
cmmands
done
set +f
This just seems like a bit of a bodge, I mean there must be a more elegant way of doing it? If not I would at least like to check if globbing is on or off first, then do what I need to do before returning it to its original setting.
Any suggestions most appreciated.
One of the settings in the config file is a space delimited list of file masks, which I want to build into find command like so:
\ ( -iname 'mask1*.txt' -o 'mask2.???' -o '[0-9]mask3.old' \ )
As the for loop works through a space delimited list I thought it would be perfect, however bash understandably wants to glob all my masks before running through them. Quoting just breaks the output, so I've fixed it by turning off globbing:
set -f
For mask in $masklist; do
cmmands
done
set +f
This just seems like a bit of a bodge, I mean there must be a more elegant way of doing it? If not I would at least like to check if globbing is on or off first, then do what I need to do before returning it to its original setting.
Any suggestions most appreciated.