I want to delete and 0th element of array in shell scrpit and also shift all others to one level up.
"unset" is what you are looking for.
unset arr[3]
My code sample follows:
#!/bin/bash
example[1]="one"
example[2]="two"
example[3]="three"
example[4]="four"
example[5]="five"
echo "A simple list, iterate over it to show elements"
for i in "${example[@]}"; do
echo $i;
done;
echo "Unsetting 3rd element of array with: unset example[3]"
unset example[3]
echo
echo "Iterate over the modified list."
for i in "${example[@]}"; do
echo $i;
done;
And then I tested it
-bash-3.00$ ./test.sh
A simple list, iterate over it to show elements
one
two
three
four
five
Unsetting 3rd element of array with: unset example[3]
Iterate over the modified list.
one
two
four
five
array=( a b c d e f g h i j k l ) ## define array
unset array[0] ## remove element
array=( "${array[@]}" ) ## pack array
printf "%s\n" "${array[@]}" ## print array