Posts

Showing posts with the label funny

Simple Bash Script to Reverse Your Name and Output it

Just a quick script to reverse some input, using Bash and the FOSS "rev" program. It's amazing how easy it is to manipulate things with Bash. I love it! Bash script version: #!/bin/bash #Simple script to reverse an input name echo "Enter your name";read 'myname' echo "Your name spelled backwards is: $( echo $myname | rev )" exit 0 One-liner version: echo -n "what is your name?";read name;echo "$name" |rev Or how about this more ridiculous example (one that doesn't use the "rev" program): #!/bin/bash #Simple script to reverse an input name   echo -n "Enter your name:"   read myname   numChars=$(echo -n "$myname" |wc -c)   revname=   while [ $numChars -gt 0 ]   do       revname=$revname$(echo -n "$myname"|cut -b$numChars)       numChars=$(expr $numChars - 1)  done echo "Your name spelled backwards is: $revname" exit 0 Ridic...