I want to write a script that loops through 15 strings (array possibly?) Is that possible?
Something like:
for databaseName in listOfNames
then
# Do something
end
I want to write a script that loops through 15 strings (array possibly?) Is that possible?
Something like:
for databaseName in listOfNames
then
# Do something
end
Try this. It is working and tested.
Possible first line of every Bash script/session:
Use e.g.:
May consider:
echo
interprets-e
as option hereThis is similar to user2533809's answer, but each file will be executed as a separate command.
The declare array doesn't work for Korn shell. Use the below example for the Korn shell:
Surprised that nobody's posted this yet -- if you need the indices of the elements while you're looping through the array, you can do this:
Output:
I find this a lot more elegant than the "traditional" for-loop style (
for (( i=0; i<${#arr[@]}; i++ ))
).(
${!arr[@]}
and$i
don't need to be quoted because they're just numbers; some would suggest quoting them anyway, but that's just personal preference.)I loop through an array of my projects for a
git pull
update: