Bash Program to Check Whether the Given String is a Palindrome or Not Last Updated : 26 Dec, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report Given a string str, find whether the given string is palindrome or not using Bash Scripting. A string is called a palindrome string if the reverse of the string is the same as the original string. Examples: Input: str= "GFG" Output: GFG is a palindrome string. Explanation: Reverse of "GFG" is "GFG", hence it is palindrome. Input: bash Output: bash is not a palindrome string. Explanation: Reverse of "bash" is "hsab", hence it is not palindrome. Shell Script to Check Whether the Given String is a Palindrome or Not #!/bin/bash read -p "Enter a string: " input_string # Reverse the string and compare with the original if [[ "$input_string" == "$(rev <<< "$input_string")" ]]; then echo "The entered string '$input_string' is a palindrome."else echo "The entered string '$input_string' is not a palindrome."fi Save the above script in a file, for example, example.sh. Make it executable by running: chmod +x example.shYou can then execute the script: ./example.shExplanation: `read -p "Enter a string: " input_string`: This line prompts the user to enter a string and stores their input in the variable `input_string`.`if [[ "$input_string" == "$(rev <<< "$input_string")" ]]; then`: This line starts an if statement. It checks if the entered string is equal to its reverse. Here's how it works:`"$(rev <<< "$input_string")"`: This part uses the `rev` command to reverse the entered string. The `<<<` is a "here-string" that provides the string as input to rev.`"${input_string}" == "$(rev <<< "$input_string")"`: This compares the original string with its reversed version.If the comparison is true, the script executes the commands inside the `then` block.echo "The entered string '$input_string' is a palindrome.": If the entered string is a palindrome (i.e., it reads the same backward as forward), this line prints a message indicating that the string is a palindrome.else: If the comparison in the `if` statement is false, meaning the string is not a palindrome, the script moves to the `else` block.echo "The entered string '$input_string' is not a palindrome.": This line prints a message indicating that the string is not a palindrome.Time Complexity: O(n) , Auxiliary Space: O(n) Comment More infoAdvertise with us Next Article TCS Coding Practice Question | Palindrome String A abhishek9202 Follow Improve Article Tags : Linux-Unix Linux-basic-commands Similar Reads Bash program to check if the Number is a Palindrome Given a number num, find whether the given number is palindrome or not using Bash Scripting. Examples: Input : 666 Output : Number is palindrome Input : 45667 Output : Number is NOT palindrome Approach To find the given number is palindrome just check if the number is same from beginning and the end 1 min read TCS Coding Practice Question | Palindrome String Given a string, the task is to check if this String is Palindrome or not using Command Line Arguments. Examples: Input: str = "Geeks" Output: No Input: str = "GFG" Output: Yes Approach: Since the string is entered as Command line Argument, there is no need for a dedicated input line Extract the inpu 3 min read TCS Coding Practice Question | Palindrome String Given a string, the task is to check if this String is Palindrome or not using Command Line Arguments. Examples: Input: str = "Geeks" Output: No Input: str = "GFG" Output: Yes Approach: Since the string is entered as Command line Argument, there is no need for a dedicated input line Extract the inpu 3 min read Check given string is oddly palindrome or not Given string str, the task is to check if characters at the odd indexes of str form a palindrome string or not. If not then print "No" else print "Yes".Examples: Input: str = "osafdfgsg", N = 9 Output: Yes Explanation: Odd indexed characters are = { s, f, f, s } so it will make palindromic string, " 6 min read Check if all the palindromic sub-strings are of odd length Given a string 's' check if all of its palindromic sub-strings are of odd length or not. If yes then print "YES" or "NO" otherwise. Examples: Input: str = "geeksforgeeks" Output: NO Since, "ee" is a palindromic sub-string of even length. Input: str = "madamimadam" Output: YES Brute Force Approach: S 10 min read C++ Program to Check if a Given String is Palindrome or Not A string is said to be palindrome if the reverse of the string is the same as the original string. In this article, we will check whether the given string is palindrome or not in C++.ExamplesInput: str = "ABCDCBA"Output: "ABCDCBA" is palindromeExplanation: Reverse of the string str is "ABCDCBA". So, 4 min read Like