What are Alternative Ways to Reverse a String from Shell?

LinuxOperating SystemOpen Source

In the Linux shell, we have predefined commands to return a reversed string. Anyone can use these commands for reversing an output of the program.

Perl Command

It is a general-purpose programming language in Linux.

Input

perl -ne 'chomp;print scalar reverse . "\n";'<<<”Hello"

Output

olleH

Rev Command

It is an inbuilt program to reverse the line of character.

Input

rev<<<"Hello yam"
OR
echo “Hello yam” | rev

Output

olleH may

Conclusion

In this article, we discuss the basic understanding of shell scripting. It also addressed reversing a string using shell programming and some alternative inbuilt commands of Linux. Creating shell scripts becomes easy if you know how to work on shell and control the flow of shell programs. I hope you find this article helpful.

Published on 29-Nov-2021 10:47:30