Skip to content

Instantly share code, notes, and snippets.

@mebubo
Created August 24, 2012 12:36
Show Gist options
  • Save mebubo/3450086 to your computer and use it in GitHub Desktop.
Save mebubo/3450086 to your computer and use it in GitHub Desktop.
Reverse a string in bash
#!/bin/bash
# reverse a string
reverse () {
local REVERSED=""
ORIGINAL=$1
for i in $(seq 0 $(( ${#ORIGINAL} - 1 )) ); do
REVERSED=${ORIGINAL:${i}:1}$REVERSED
done
echo $REVERSED
}
reverse "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment