Syndicate content
A female sysop is a sysopette
Updated: 1 hour 20 min ago

Bash Arrays

Wed, 2014-08-27 17:47

Arrays are helpful, and I’ll give some examples for reference. They can be a little bit confusing, but once you get used to them, it’s easy!

First you initialize the arrays

cat[1]="Bub"
cat[2]="Grumpy"
cat[3]="Luna"

feat[1]="cute"
feat[2]="terrible"
feat[3]="fashion"

Then you use them as you wish. You can, at first, just list them individually

echo "${cat[3]} is ${feat[1]}"

or list all of the items in a specific array
echo “Cats I like: ${cat[@]}”

Something like that would also work:

for i in {1..3}
do
echo "${cat[i]} is ${feat[i]}!"
done

That opens many possibilities. Life is not only about internet cats (although it sometimes seems so).

Make good use of your arrays, they’re great!

(I takes me 8 months to update the site and I write a silly post about bash arrays, I know. Sorry, I was thinking about them.)

Categories: LinuxChix bloggers