I\'m writing a bash script which shall search in multiple files.
The problem I\'m encountering is that I can\'t egrep an undetermined number of variables passed as param
A safe eval could be a good solution
#!/bin/bash if [[ $# -gt 0 ]]; then TEMP=("grep" "-e" "\"\$1\"" "*") for (( I = 2; I <= $#; ++I )); do TEMP=("${TEMP[@]}" "|" "egrep" "-e" "\"\$${I}\"") done eval "${TEMP[@]}" fi
To run it:
bash script.sh A B C