I'm wondering:
- isIs there a way to avoid
eval
(security??)? - isIs there a better way or place to use
shopt -s nullglob
? - doesDoes
shopt -u nullglob
always need to be unset through each iteration? - isIs there a smarter way to do define a list of locations?
#!/bin/bash if [ $# -eq 0 ] then echo specify at least a regular expression pattern exit 1 fi # make an array. Use 'single quotes' SEARCH_LOCATIONS=( '$BIN_HOME/*' '$PBIN_HOME/*' '$PBIN_HOME/lib/*' '$SH_HOME/* ' '$SH_HOME/*/*' '$PROD_HOME/psp/*.psp' '$PROD_HOME/sql/*.sql' '$PROD_HOME/sql/*/*.sql' '$PROD_HOME/rpt/[A-Z]*.rpt' '$PROD_HOME/script/*' '$PROD_HOME/fmb/[A-Z]*.pll' '$PROD_HOME/xml/[A-Z]*.pld' '$PROD_HOME/fmb/[A-Z]*.mmb' '$PROD_HOME/xml/[A-Z]*.xml' '$PROD_HOME/cgi/*' '$ELETTUS_HOME/*' '$ELETTUS_HOME/*/*' '$PROD_HOME/guicommon/*' ) for LOCATION in ${SEARCH_LOCATIONS[@]} do # ---- evaluate array contents echo -------------------------------------------------------------------------------- echo "$LOCATION" echo eval declare location=$LOCATION if [[ $location != /u2/* ]] then echo $LOCATION is not a part of Lettus system >&2 echo continue fi shopt -s nullglob grep -E -I -d skip "$@" $location shopt -u nullglob done
#!/bin/bash
if [ $# -eq 0 ]
then
echo specify at least a regular expression pattern
exit 1
fi
# make an array. Use 'single quotes'
SEARCH_LOCATIONS=(
'$BIN_HOME/*'
'$PBIN_HOME/*'
'$PBIN_HOME/lib/*'
'$SH_HOME/* '
'$SH_HOME/*/*'
'$PROD_HOME/psp/*.psp'
'$PROD_HOME/sql/*.sql'
'$PROD_HOME/sql/*/*.sql'
'$PROD_HOME/rpt/[A-Z]*.rpt'
'$PROD_HOME/script/*'
'$PROD_HOME/fmb/[A-Z]*.pll'
'$PROD_HOME/xml/[A-Z]*.pld'
'$PROD_HOME/fmb/[A-Z]*.mmb'
'$PROD_HOME/xml/[A-Z]*.xml'
'$PROD_HOME/cgi/*'
'$ELETTUS_HOME/*'
'$ELETTUS_HOME/*/*'
'$PROD_HOME/guicommon/*'
)
for LOCATION in ${SEARCH_LOCATIONS[@]}
do
# ---- evaluate array contents
echo --------------------------------------------------------------------------------
echo "$LOCATION"
echo
eval declare location=$LOCATION
if [[ $location != /u2/* ]]
then
echo $LOCATION is not a part of Lettus system >&2
echo
continue
fi
shopt -s nullglob
grep -E -I -d skip "$@" $location
shopt -u nullglob
done