LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-26-2013, 10:51 AM   #1
priyanka28
LQ Newbie
 
Registered: Jul 2013
Posts: 1

Rep: Reputation: Disabled
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
 
Old 07-27-2013, 04:47 AM   #2
SAbhi
Member
 
Registered: Aug 2009
Location: Bangaluru, India
Distribution: CentOS 6.5, SuSE SLED/ SLES 10.2 SP2 /11.2, Fedora 11/16
Posts: 665

Rep: Reputation: Disabled
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 ?
 
Old 07-27-2013, 05:29 AM   #3
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
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 '(('.
 
Old 07-29-2013, 06:00 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,417

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
"Command not found" error using expr in shell script Harish sharma Linux - Newbie 17 11-08-2012 06:53 AM
[SOLVED] Error Executing the script. pinga123 Linux - Newbie 3 07-08-2010 11:34 PM
How to multiply with expr? ( expr 3 * 4 doesn't work, though expr 3 + 4 does) lumix Linux - General 5 02-25-2009 06:31 PM
FC6 firefox hangs with "expr: syntax error" srn1 Fedora 0 08-16-2007 10:45 PM
expr syntax error baosheng Programming 4 06-09-2005 04:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration