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 :)
If You Liked This Post Please Take a Time To Share This Post

Thanks sir, for publish this shell script.
ReplyDeleteCan you explain me the script. I am not able to undestand.
ReplyDeleteTUMSE NA HO PAYEGA BETA...
Deletemujse hopayenga ullukkapattttaaaaaa
Deletekameene
shell script wrong... in line 4: if i include the first line
ReplyDelete"#!/bin/bash"
it shows :
line 4: ((: i=#3-1: syntax error: operand expected (error token is "#3-1")
wrong script
ReplyDeletemistake in line4
bloody fool
This was very clear and well explained! Thanks. The article of Color Blindness Test is simple and informative for everyone. If traffic lights or warning signs sometimes look unclear, a color blind test can help explain potential vision challenges.
ReplyDelete