Reputation: 6328
I am new in Shell Scripting
, however i am friendly with Java Maps
. I Just wanted to know that how can i use Map
facility in Shell Scripting
. Below is the facility i need to use in shell-
HashMap<String, ArrayList<String>> users = new HashMap<String, ArrayList<String>>();
String username = "test_user1";
String address = "test_user1_address";
String emailId = "test_user1_emailId";
ArrayList<String> values = new ArrayList<String>();
values.add(address);
values.add(emailId);
users.put(username, values);
String anotherUser = "test_user2";
if (users.containsKey(anotherUser)) {
System.out.println("Do some stuff here");
}
In short, i want to use a Map
, which has String
as key
, either Vector
or ArrayList
as value (otherwise i have live with Arrays
instead of ArrayList
and manually take care of indexes
) , put
method to insert
and one more method to check the presence of the key
in the existing Map
.
The above code is a sample code. Thank you in advance.
Upvotes: 0
Views: 368
Reputation: 798774
bash does not support nested structures like this. Either use separate variables for each array, or use something more capable such as Python.
Upvotes: 3