#!/bin/bash
things=( first second third )
for i in ${things[@]}
do
echo $i
done
If the number of array elements is large, it can be useful to have one element per line:
things=( \
first \
second \
third \
)
Using GNU/Linux through creative laziness (and other topics as they strike my fancy)
#!/bin/bash
things=( first second third )
for i in ${things[@]}
do
echo $i
done
things=( \
first \
second \
third \
)
3 comments:
If you want to loop through an array literally you can do it like this:
for i in file1 file2 file3
do
...
done
thanks for documenting syntax. I wish I knew what the @ sign is doing. is the another variable indicator like $?
anyway I plan to write a script to remove my log and aux files after compiling a xelatex document.
The @ symbol is an array subscript which causes the word (things[@]) to expand to all members of the things array. (See the "Arrays" section of the bash man page.)
Post a Comment