Jun 4, 2017

Bash: The most useless command

After many years working with the bourne again shell i  am still learning some commands, which i never used.
I am completely convinced that i discovered the most useless command:
The manpage says:
rev - reverse lines characterwise
 Is there anything, where i can use this command?

Ok. I can check if a word is a palindrome (like 123321 or otto):

# Shell script to test if a string is a palindrome
# This simply uses the 'rev' command found in util-linux-ng package
# and checks if the reverse of the string is same as the original
 echo "Enter a String : "
read string
if [ "$(echo $string | rev)" = "$string" ]
 echo "\"$string\" IS a Palindrome"
 echo "\"$string\" IS NOT a Palindrome"
This script i found in here.

Has anyone used the rev command for something reasonable?
Please write a comment!

More useless commands can be found here.

1 comment:

  1. There is another command "yes". That just outputs "y" in the standard output. This is the most useless. Most of the bash commands, when used alone are useless. Each of them are designed to do a very specific job. These gives you a toolbox. To achieve a task then you can use more than one commands in conjunction to do complex tasks. For the case of rev, let's say, you have a log file from which you filter out lines with some specific paths related to some kind of software crash or whatever. You need to find last component of the path (ex. /use/bin/bash , need to get "bash"). In this case you can first rev the line and then cut the first field and the rev again. cat log | grep pattern | rev | cut -d '/' -f 1 | rev . You can do this with awk, or any other stuffs, but the main idea of the useless commands or the commands of very little use is to provide basic functionality, which in combination can bring extreme flexibility and power.