Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.
clear
echo "Enter a number"
read n
sd=0
rev=0

while [ $n -gt 0 ]
do
    sd=$(( $n % 10 ))
    rev=$(( $rev *\ 10 + $sd ))
    n=$(( $n / 10 ))
done

echo "Reverse number of entered digit is $rev"

From the above code I am unable to get the required output. Instead, this error is displayed.

./Display: line 17: 0 *\ 10 + 4 : syntax error: operand expected (error token is "\ 10 + 4 ")
Reverse number of entered digit is 0

I don't know why this error is displayed, please help me to figure it out.

share|improve this question
1  
*\ is not a valid arithmetic operator in bash. What is your expected input and output? –  Chris Down Feb 24 '13 at 6:27
add comment

3 Answers 3

Numbers are text too. Text can be reversed with rev without any arythmetic.

#!/bin/bash
clear
read -p "Enter a number: " num
echo $num | rev
share|improve this answer
add comment

The error had already pointed out the problem clearly: 0 *\ 10 + 4 isn't a valid arithmetic expression when shell try to evaluate it.

I believe *\ is a typo of *, fix this typo and the script will be ok.

share|improve this answer
add comment

*\ is not the valid expression. Instead, try * which removes the special meaning of the character *. The character * is a wildcard character, which is why the error appeared.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.