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 07-21-2004, 02:24 AM   #1
pragti
LQ Newbie
 
Registered: Feb 2004
Posts: 16

Rep: Reputation: 0
EXPR in shell


a2=1
b=2
c=3
expr a$b + 3 --------giving wrong ans
expr `echo \$a$b + 3` ---------giving wrong ans

is giving error how to solve
 
Old 07-21-2004, 02:35 AM   #2
Vookimedlo
Member
 
Registered: Jul 2004
Location: Czech Republic - Roudnice nad Labem
Distribution: Debian
Posts: 253

Rep: Reputation: 34
and what would you like to do?
 
Old 07-21-2004, 02:41 AM   #3
pragti
LQ Newbie
 
Registered: Feb 2004
Posts: 16

Original Poster
Rep: Reputation: 0
my application need me to add 3 to a variable a?.the variable is dependent on the value of b.i.e if b=7 then i need to add 3 to a7
if b=10 then i need to add 3 to a10
 
Old 07-21-2004, 03:54 PM   #4
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
use 3 variables

a=7
b=7
A=

if [ "$b" = 7 ]; then
A=a`expr $a + 3`
fi
echo $A

Last edited by keefaz; 07-21-2004 at 03:59 PM.
 
  


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
About how to use expr naihe2010 Programming 2 10-31-2005 06:28 AM
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

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

All times are GMT -5. The time now is 01:31 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