Is it possible to create and use a list of objects in BASH environment

I am working in an environment bash

and trying to make a list of sample names; each of which will be passed to a command set. Creating lists in R and Python is very easy. However, I have not been able to figure out if and how equivalent list variables can be created and accessed in bash

.

For example, to create a list in python, you could write:

samples=[sample1 sample2 sample3]

      

To access the first variable in the list, one can use:

currentSample = samples[0]

      

Is it possible to perform similar operations bash

with a list of text strings?

+3


source to share


1 answer


Here's an example of what you want:

samples=(sample1 sample2 sample3)
currentSample=${samples[0]}
echo "$currentSample"
echo "${samples[0]}"

      

Output:



sample1 
sample1

      

As you can see, you can assign the value of the array to a variable, or use its value directly.

+5


source







All Articles