ITYM:
Array=(11 22 33 44 55)
Array[0]=${Array[3]} # "3", not "$3"
O que teria resultado em:
Array=(44 22 33 44 55)
$3 se expande para o terceiro argumento posicional (argumento para o shell script), se estiver vazio (como costuma ser em um shell interativo), então ${array[$3]} é o mesmo que ${array[0]} ou $array .
Se você queria alcançar:
Array=(55 11 22 33 44)
Você precisa fazer:
Array=("${Array[4]}" "${Array[@]:0:4}")
Ou mais geralmente:
Array=("${Array[@]: -1}" "${Array[@]:0:${#Array[@]}-1}")
Com zsh , você também pode fazer:
Array[1,0]=$Array[-1] # insert the last element at the beginning
Array[-1]=() # remove the last element
ou:
Array=("$Array[-1]" "${(@)Array[1,-2]}")
com yash :
array -i Array 0 "${Array[-1]}"
array -d Array -1
Com fish (supondo que a matriz tenha pelo menos dois elementos):
set Array 11 22 33 44 55
set Array $Array[-1 1..-2]