Skip to content

Instantly share code, notes, and snippets.

@c00kiemon5ter
Created June 27, 2011 01:24
Show Gist options
  • Save c00kiemon5ter/1048167 to your computer and use it in GitHub Desktop.
Save c00kiemon5ter/1048167 to your computer and use it in GitHub Desktop.
reverse an array
#!/bin/bash
reverse_array() {
local _array=$1
shift
unset $_array
while (( $# != 0 ))
do
printf -v $_array[$#-1] "%s" "$1"
shift
done
}
A=(a b c d e f)
reverse_array B "${A[@]}"
echo "${A[@]}
reversed is
${B[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment