Before my question is closed ... I put here some answers
-Create an empty list
arr=()
-Add an element to the list
~~Not sure about this. I thought it was
arr=($newvalue "$arr[@]") but it is not.~~
arr=( $newvalue "${arr[@]}")
- Check if the list is empty
if ((${#arr[@]})); then #the number is not 0
echo "array is not empty"
else
echo "array is empty"
fi
echo ${arr[0]}
I think it is very important to put all these in a question and not going all around the internet to find the answers so here it goes
#create an empty array
arr=()
#arr=("eee")
echo "empty array"
echo ${arr[@]}
newvalue=000
#add new element
echo "add elements"
arr=("new_element" "${arr[@]}")
echo ${arr[@]}
arr=( $newvalue "${arr[@]}")
echo ${arr[@]}
echo "first element and number of elements"
echo ${arr[0]} #refer to an element by index
echo ${#arr[@]} #number
echo "is it empty"
if ((${#arr[@]})); then #the number is not 0
echo "array is not empty"
else
echo "array is empty"
fi
echo "delete element"
arr=("${arr[@]/$newvalue}" )
echo ${arr[@]}