Wednesday, April 6, 2022

Linux Shell Script Arrays

Arrays

It is the collection of elements under a single name 

Below are some operations on Array

# To declare static Array
arr=(prakhar ankit 1 rishabh manish abhinav)

# To print all elements of array
echo ${arr[@]}
echo ${arr[*]}
echo ${arr[@]:0}
echo ${arr[*]:0}

# To print first element
echo ${arr[0]}
echo ${arr}

# To print a particular element
echo ${arr[3]}
echo ${arr[1]}
#To print element 4th index onwards
echo ${arr[*]:4}

#To print element for a particular range
echo ${arr[@]:1:4}

#To print the length of first element
echo ${#arr[0]}

# To find how many elements in an array
echo ${#arr[@]}

0 comments:

Post a Comment