Simple Add - Problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple Add - Problem
# 1  
Old 08-18-2008
Simple Add - Problem

#!/bin/ksh
echo "ADDITION OF TWO NUMBERS"
echo " "
echo "ENTER FIRST NUMBER"
read no1
echo "ENTER SECOND NUMBER"
read no2
echo " "
no3=expr '$no1 + $no2'
echo "ADDITION OF TWO NUMBERS IS :" $no3


Please recorrect..and help asap
# 2  
Old 08-18-2008
any1 there...

pls HELP
# 3  
Old 08-18-2008
The use of single quotes prevents the values of $no1 and $no2 from being expanded. Furthermore, in order to actually capture output from a command, you have to execute it -- variable=value simply assigns value to variable, it's not executed as a command. What you want is variable=`command` with backticks (ASCII 96, not regular straight quotes) around the command you want to execute.

Code:
no3=`expr "$no1" + "$no2"`

It is against the rules to "bump" your own question, and actually reduces the likelihood that somebody will respond. It is extremely optimistic to expect a reply in less than one hour.
# 4  
Old 08-18-2008
Thanks... a million...!!!
# 5  
Old 08-18-2008
Thanks Era...!!!
# 6  
Old 08-19-2008
Also statement should be like

Code:
let no3=`expr "$no1" + "$no2"`

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

simple wc problem

Hi there, Im sure there is a simple explanation for this but I have a file like this with no balnk lines peter paul john I run the command # var=`grep paul file.txt` # echo $var paul # echo $var | wc -l 1 but when I grep for a value that isnt in the file, i still... (4 Replies)
Discussion started by: rethink
4 Replies

2. Shell Programming and Scripting

simple array problem

Hello experts, I need help in my code. I have an input file like this: 100814 1205 1724127 7451382 -10 00:30:1b:48:92:3a 100814 1206 1724127 7451382 -72 00:30:1b:48:92:3a 100814 1207 1724127 7451382 -72 00:30:1b:48:90:3b 100814 1208 1724127 7451382 -72 00:30:1b:48:92:3a 100814 1209... (12 Replies)
Discussion started by: enes71
12 Replies

3. Shell Programming and Scripting

Please help me with a simple problem

Hi, I have a very simple script like below: for n in 10 20 30 do for a in 30 40 50 60 70 80 do for r in 2 3 4 5 6 7 do m=$((r*a)) count=1 while do echo "a = " $a ", m = " $m ", n = " $n ... (2 Replies)
Discussion started by: Dark2Bright
2 Replies

4. Programming

Simple g++ compilation problem

I'm trying to port some code over to unix Solaris. I'm not really a unix programmer so I'm sure this is something straight-forwards but I'm getting the following: > g++ -c CTrade.cpp In file included from CTrade.cpp:1: stdafx.h:6: warning: `#pragma once' is obsolete CTrade.cpp:4: iostream: No... (1 Reply)
Discussion started by: achartley
1 Replies

5. UNIX for Dummies Questions & Answers

simple fork() problem

I have this little program ... int main(void){ printf("Before"); fork(); printf("After"); } output is this..... BeforeAfterBeforeAfter Shouldnt it be.....BeforeAfterAfter After parent is forked child receives the copy of program and continues from next statement... (3 Replies)
Discussion started by: joker40
3 Replies

6. Shell Programming and Scripting

simple jsp problem.

I have my jsp page located at /install/apache-tomcat-5.5.29/webapps/jsp-examples/light/login.jsp There fore i will have to use following url to access it. localhost:8080/jsp-examples/light/login.jsp How would i make this little shorter like. localhost:8080/login.jsp I m using... (13 Replies)
Discussion started by: pinga123
13 Replies

7. Shell Programming and Scripting

Simple while-loop problem

Maybe because its Friday, but I can't get a simple while loop to work! #!bin/bash i=0 while do echo "Hello" ((i++)) done (17 Replies)
Discussion started by: linuxkid
17 Replies

8. Shell Programming and Scripting

Simple regex problem?

Hi all, I am looking to create words from a sentence which adhere to a custom search pattern from my website: Example: ! +! / += ~ where the terms ! = not, +! = AND NOT, += - and equals and ~ = can be like.... Now here is the issue...i want to split a sentence like the one above on... (1 Reply)
Discussion started by: muay_tb
1 Replies

9. Shell Programming and Scripting

Simple script problem

Hi everyone - I am sure this is a really simple problem but I'm a total noob at Linux scripting: I wanted to create a script that allows me to compare the current week number to the contents of a text file in my home directory: VAR1='date +%V' VAR2='cat /home/fred/file.txt' ... (6 Replies)
Discussion started by: FiniteRed
6 Replies

10. UNIX for Advanced & Expert Users

A simple Samba problem, please help

Hi, I have successfully setup my Samba server on my Sun Solaris 8 Sparc machine. My Win2000 workstation is able to see the unix worstation and its shared directory from Network Neighborhood. However, the Unix workstation appears as Ip address instead of Hostname on my network neighborhood... (5 Replies)
Discussion started by: champion
5 Replies
Login or Register to Ask a Question