linux - Grep multiple bash parameters -
i'm writing bash script shall search in multiple files.
the problem i'm encountering can't egrep undetermined number of variables passed parameters bash script
i want following:
given random number of parameters. i.e:
./searchline.sh b c do grep on first one, , egrep result rest:
grep "a" * | egrep b | egrep c what i've tried build string egreps:
for j in "${@:2}"; additionalsearch="$additionalsearch | egrep $j"; done grep "$1" * "$additionalsearch" but somehow won't work, seems bash not treating "egrep" string egrep.
do guys have advice?
by way, side note, i'm not able create auxiliary file grep -f out of line guess. note, number of parameters passed bash script variable, can't egrep "$2" | egrep "$3".
thanks in advance.
fernando
a safe eval solution
#!/bin/bash if [[ $# -gt 0 ]]; temp=("grep" "-e" "\"\$1\"" "*") (( = 2; <= $#; ++i )); temp=("${temp[@]}" "|" "egrep" "-e" "\"\$${i}\"") done eval "${temp[@]}" fi to run it:
bash script.sh b c
Comments
Post a Comment