|
We know what an array is. An array is a variable which can store multiple values in the same name. These values can be accessed by using the subscripts. The whole of the array can be accessed by just mentioning the array name without any subscripts. Let us see some of the important operations using array in BASH with the help of the below script.
The output of the above script would be
$ ./array.sh
The array contains 4 members. They are:
0: ram
1: rick
2: sittik
3: rahim
Adding bill to the end of the array
Listing all the elements in the array
ram rick sittik rahim bill
Listing all the elements in the array
ram rick sittik rahim bill
Deleting "rick"
Now the array is
ram sittik rahim bill
length of 3rd element in the array
6
Deleting the whole array
Hi
ReplyDeleteWhile running your above program by copying and pasting, i got error in line:5. Could not able to resolve it. But it seems there is some syntax error.
./array_program: 5: ./array_program: Syntax error: "(" unexpected
Could you please correct it ?
Regards
Tom
got the answer. I was running it in /bin/sh. But it should be /bin/bash
DeleteThank you
Regards
Tom