LinuxQuestions.org
Help answer threads with 0 replies.
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 10-31-2005, 12:51 AM   #1
naihe2010
Member
 
Registered: Oct 2005
Location: China
Distribution: ArchLinux
Posts: 103

Rep: Reputation: 15
About how to use expr


I use "expr" to do something,and it can't work.

Code:
$ expr 1+2
1+2
$ expr "1+2"
1+2
$ expr a=d
a=d
$ expr 10
10
$ expr abcde
abcde
$ expr abc +12
expr: syntax error
$ expr abc+12
abc+12
I think the first line is right,but it can't work,so I tried the others.
 
Old 10-31-2005, 02:41 AM   #2
zhangmaike
Member
 
Registered: Oct 2004
Distribution: Slackware
Posts: 376

Rep: Reputation: 31
You need spaces between the numbers and the operators.

Code:
$ expr 1 + 2
3
In bash, you don't need spaces if you use $(( ))

Code:
$ echo $((1+2))
3
 
Old 10-31-2005, 06:28 AM   #3
naihe2010
Member
 
Registered: Oct 2005
Location: China
Distribution: ArchLinux
Posts: 103

Original Poster
Rep: Reputation: 15
Very thank you.
 
  


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
expr syntax error baosheng Programming 4 06-09-2005 03:32 PM
simple expr izza_azhar Programming 3 01-17-2005 07:38 PM
Usage of 'expr' command subu_s Programming 2 12-03-2004 01:23 AM
Newbie : expr scripting error hrg Linux - General 3 08-13-2004 10:24 AM
EXPR in shell pragti Programming 3 07-21-2004 03:54 PM

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

All times are GMT -5. The time now is 09:15 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
Open Source Consulting | Domain Registration