Q: How do I reverse a string in Linux/Unix?
Ans:
#!/bin/bash
read -p "Enter string:" string
len=${#string}
for (( i=$len-1; i>=0; i-- ))
do
# "${string:$i:1}"extract single single character from string.
reverse="$reverse${string:$i:1}"
done
echo "$reverse"
Output
Enjoy :)
Saturday, November 24, 2012
0 comments:
Post a Comment