I have one file with a list of names. I need to loop through all names in this file from an external file with a shell script. How can I do that?
Example files:
scripts/names.txt
alison
barb
charlie
david
scripts/script.sh
NAMES="" #names from names.txt file
for NAME in $NAMES; do
echo "$NAME"
done
How can I explode the names.txt file into an array in a separate shell script?
One way would be:
EDIT:
Note that the loop gets executed in a sub-shell, so any modified variables will be local, except if you declare them withdeclareoutside the loop.Dennis Williamson is right. Sorry, must have used piped constructs too often and got confused.