Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Since it is allowed to do a=5 ; echo $a, I was wondering whether or not it is possible to declare lists and other data structures (such as tuples, dictionaries) in the terminal?

And if so, are they mutable or they must be unset first?

share|improve this question
up vote 6 down vote accepted

You can also use array; the simplest method of creating an array variable is to assign a value to one of its indices:


or, with:

TEST=(zero one two)

now, you access it as follows:



echo "First Index: ${TEST[0]}"

or you can access all the items in an array in one of the following ways:


For more help, read this usefull guide

share|improve this answer
Very useful, thank you ! – user253956 May 5 '14 at 18:27
@user253956 You're welcome. – girardengo May 5 '14 at 18:31

Is it possible. You can use lists and its mutable.

Try something like this:

arr=(1 2 3)  
echo ${list}
echo ${list[1]}
echo ${list}
echo ${list[1]}
echo ${list} | xargs -n 1

And, for a dictionary you will need to build a hash function.

For know how to do this:

Its easy to iterate over a list with xargs and you also can add unit tests to your script:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.