LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-06-2005, 02:35 AM   #1
baosheng
Member
 
Registered: Oct 2004
Location: Lubbock, TX, USA
Distribution: Ubuntu 7.10
Posts: 74

Rep: Reputation: 15
expr syntax error


Hi guys.I wrote a shell script.But it doesn't work well.Can you help me?
The script is

#!/bin/sh
echo "please input a file name"
read file_name
date
num=1
while [ $num -lt 10 ]
do
gzip $file_name
gzip -d *.gz
num=`expr $num +1`
done
date

and this is the executing result
[root@myENIAC program]# sh deflate_time.sh
please input a file name
xlxfg512.txt
Mon Jun 6 15:30:55 CST 2005
expr: syntax error
deflate_time.sh: line 6: [: -lt: unary operator expected
Mon Jun 6 15:30:55 CST 2005
 
Old 06-06-2005, 02:55 AM   #2
slackie1000
Senior Member
 
Registered: Dec 2003
Location: Brasil
Distribution: Arch
Posts: 1,037

Rep: Reputation: 46
hi there,
i think this post is more appropriate in programming...
anyway...
change the line
Code:
num=`expr $num +1`
per
Code:
num=$((num+1))
a tip: use the bb code tags... make it easier to read.. thanks.
regards
slackie1000
 
Old 06-06-2005, 03:14 AM   #3
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

Rep: Reputation: 475Reputation: 475Reputation: 475Reputation: 475Reputation: 475
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 06-06-2005, 03:14 AM   #4
baosheng
Member
 
Registered: Oct 2004
Location: Lubbock, TX, USA
Distribution: Ubuntu 7.10
Posts: 74

Original Poster
Rep: Reputation: 15
it ok now
thanks
 
Old 06-09-2005, 03:32 PM   #5
osvaldomarques
Member
 
Registered: Jul 2004
Location: Rio de Janeiro - Brazil
Distribution: Conectiva 10 - Conectiva 8 - Slackware 9 - starting with LFS
Posts: 519

Rep: Reputation: 34
Hi Baosheng,

Just for the record, the problem was given by the expression evaluator "expr" detected a syntax error; you wrote the expression as
Code:
num=`expr $num +1`
instead of
Code:
num=`expr $num + 1`
As the expression evaluator received just 2 arguments, it gave a syntax error, returning an empty string to "num" variable.
As this variable is not numeric anymore, the test operator "[" returns an error as it is comparing a non numeric variable using the numeric comparator "-lt".
 
  


Reply



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
Many errors when 'make'ing (example: error: syntax error before `::' token) darkblade Linux - Software 5 03-02-2005 03:00 PM
C++ syntax error before :: token HELP, i cant find the syntax error :( qwijibow Programming 2 12-14-2004 06:09 PM
Newbie : expr scripting error hrg Linux - General 3 08-13-2004 10:24 AM
ERROR running make when installing Nvidia drivers (syntax error) randyriver10 Linux - Software 5 02-21-2004 04:51 PM
C++ syntax error bru Programming 3 01-31-2004 10:24 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

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
Open Source Consulting | Domain Registration