Saturday, May 4, 2024
6
rated 0 times [  6] [ 0]  / answers: 1 / hits: 1724  / 3 Years ago, mon, september 27, 2021, 7:35:26

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?


More From » command-line

 Answers
7

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



TEST[0]=zero
TEST[1]=one
TEST[2]=two


or, with:



TEST=(zero one two)


now, you access it as follows:



${TEST[index]}


ie



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


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



${TEST[*]}
${TEST[@]}


For more help, read this usefull guide


[#25407] Wednesday, September 29, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dicatandyca

Total Points: 486
Total Questions: 108
Total Answers: 121

Location: Greenland
Member since Wed, Jan 18, 2023
1 Year ago
dicatandyca questions
;