Multidimensional array

I am learning about bash system variables, such as $ , @ and #.

I have this piece of script implementing an array and it is doing its job just fine.

This is not the only array I will be using.

Just for ease of maintenance and more coding I would like to have the arrays in two dimensional fashion so I can put all of them in one physical place.

In pseudocode

array 

         arraySYSTEM=( "$@" )
         arrayUSB=( "$@" )
         arrayXXX=( "$@" )

I am still not to sure how the symbols $@ used in this code actually work.

So - how do I implement two dimension array using system arables?

 echo "#declare an arraySYSTEM   @line $LINENO "  
 788  arraySYSTEM=( "$@" )
 789 #temporary use lsusb commnds  
 790 set -- lsusb " Debug component SYSTEM " "TEST parameter lsusb -v" "lsusb -$
 791 echo "$#"       # number of elements in array
 792 echo "$@"       # contents  of array 
 793 # do common function  
 794                 ;; 


With no indication of what you want the second array dimension to be nor what values you want to use as indices into your array, I have no idea how to give you any guidance on this subject.

I don't find your pseudocode helpful in understanding what you're trying to do. I don't see anything indicating that there is a two dimensional array in that pseudocode and I have no idea why you would need three arrays that all contain the same number of elements and have each corresponding element of those three different arrays contain identical strings.

In line 790 of the code you showed us, there are mismatched double-quotes. That is likely to cause a syntax error somewhere in one of the following lines unless you manage to match the last quote with another mismatched double-quote on a line somewhere following line 794 in code that you haven't bothered to show us. If you have read the manual page, and there is something about these three variables that you don't understand, ask us specific questions about what you don't understand. If you just say you don't understand what $$ does, about all we can do is quote what you will find on the bash manual page.

Depending on what you're trying to do, you might also need to use an associative array instead of an indexed array. As far as I know, bash doesn't provide multi-dimensional arrays, but they can sometimes be simulated using associative arrays. Associative arrays were added to ksh in 1993. I don't know what version of bash you need in order to be able to use associative arrays.

Since you haven't bothered to tell us what operating system you're using and what version of bash you're using, we can't make many useful suggestions.

How $$ , $@ , "$@" , and $# work are all explained very clearly on the bash man page on your system and in the bash manual pages available under the "Man" tab at the top of The UNIX & Linux Forums home page.

1 Like

bash --version
GNU bash, version 4.4.12(1)-release (arm-unknown-linux-gnueabihf)

What I am trying to do is to pass variables / arguments to a common function.
At present I am using build-in "position (?) variables" "$" and need more that 10 at a time.

I was hoping multidimensional array / indexing would help , apparently not a bash

"standard "option. ( I found another source addressing the issue I'll try to use.)

It is not necessary to show your superiority attitude to beginner likes me, especially your RTFM comment was not appreciated.

Perhaps you have never made a typo in you life too.

I reviewed Don Cragun's comments and he was correct asking "annacreek" politely if he or she had reviewed the docs.

I did not see any "superior attitude" or anything negative in Don's reply, and this is a warning to annacreek.

If you insult anyone here again, especially moderators who are trying to help you, you will be banned.

Do not come here and insult people who are helping you.

1 Like

Hello!

In case you forgot to read the forum rules, here is quick copy.

Cheers.

The UNIX and Linux Forums