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