Skip to main content
deleted 96 characters in body; edited title
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

grep Grep to search for array of location targets

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

grep to search for array of location targets

I'm wondering:

  • is there a way to avoid eval (security??)
  • is there a better way or place to use shopt -s nullglob
  • does shopt -u nullglob always need to be unset through each iteration?
  • is 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

Grep to search for array of location targets

  • Is there a way to avoid eval (security)?
  • Is there a better way or place to use shopt -s nullglob?
  • Does shopt -u nullglob always need to be unset through each iteration?
  • Is there a smarter way to 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
added 1678 characters in body; edited tags
Source Link

Please review my short 65 lines of code:

I'm wondering:

  • is there a way to avoid eval (security??)
  • is there a better way or place to use shopt -s nullglob
  • does shopt -u nullglob always need to be unset through each iteration?
  • is 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

Please review my short 65 lines of code:

I'm wondering:

  • is there a way to avoid eval (security??)
  • is there a better way or place to use shopt -s nullglob
  • does shopt -u nullglob always need to be unset through each iteration?
  • is there a smarter way to do define a list of locations?

Please review my short 65 lines of code:

I'm wondering:

  • is there a way to avoid eval (security??)
  • is there a better way or place to use shopt -s nullglob
  • does shopt -u nullglob always need to be unset through each iteration?
  • is 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
Source Link

grep to search for array of location targets

Please review my short 65 lines of code:

I'm wondering:

  • is there a way to avoid eval (security??)
  • is there a better way or place to use shopt -s nullglob
  • does shopt -u nullglob always need to be unset through each iteration?
  • is there a smarter way to do define a list of locations?