LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   getting expr : syntax error while executing script (https://www.linuxquestions.org/questions/linux-newbie-8/getting-expr-syntax-error-while-executing-script-4175471012/)

priyanka28 07-26-2013 09:51 AM

getting expr : syntax error while executing script
 
getting an error for executing the following

for (( i = 1; i <= 9; i++ ))
do
for (( j = 1; j <= 9; j++ ))
do
tot=`expr $i +sj`
tmp=`expr $tot % 2`
if [ $tmp=0 ]
then
echo -e -n "\033[47m " ## for black color
else
echo -e -n "\033[40m " ## for white color
fi
done
echo -e -n "\033[47m"
echo "" ### print the new line ###
done

SAbhi 07-27-2013 03:47 AM

What you are trying to do ??
there are many mistakes in this script..

Code:

tot=`expr $i + $j`
#here goes your syntax error

Code:

echo -e -n "\033[47m " ## for black color
else
echo -e -n "\033[40m " ## for white color
fi
done
echo -e -n "\033[47m"

This will make whole your screen white unless you terminate the color code with \033[0m and produce no output. as every time the first condition become false. I dont know what you are trying to do ?

konsolebox 07-27-2013 04:29 AM

You should have spaces between your conditional operands.
Code:

if [ "$tmp" = 0 ]
And make sure you run Bash, not other shells.

Your arithmetic expressions could also be better done with (( )) as well. Run help let; help '(('.

chrism01 07-29-2013 05:00 AM

Use correct operator '-eq' & double [[ ]]
Code:

if [[ tmp -eq 0 ]]
http://tldp.org/LDP/abs/html/testcon...ml#DBLBRACKETS
http://tldp.org/LDP/abs/html/comparison-ops.html


All times are GMT -5. The time now is 09:09 PM.