multiplication shows syntax error


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers multiplication shows syntax error
# 1  
Old 04-07-2008
multiplication shows syntax error

my shell script is simple arithmetic process.my addtion,substract and divide all can be worked only except multiplication.please help me.the shell is following:
Code:
#!/usr/bin/sh
echo "enter a number1:"
read number1
echo "enter an operator:"
read operator
echo "enter a number2:"
read number2
echo "result is:"
result='expr $number1 $operator $number2'
echo $result


Last edited by Yogesh Sawant; 04-08-2008 at 06:57 AM.. Reason: added code tags
# 2  
Old 04-07-2008
What does * represent for the shell?

That should help you see what is going wrong...
# 3  
Old 04-07-2008
Since you have posted very lately a few, that give me the feeling its close to homework if not...
I will just show you that modifying just a little your script I end with:
Code:
ra:/home/vbe $ calcul   
enter a number1:
34
enter an operator:
*
enter a number2:
2
result is:
68
ra:/home/vbe $

Look at my previous post and think hard...

Last edited by Yogesh Sawant; 04-08-2008 at 06:58 AM.. Reason: added code tags
# 4  
Old 08-07-2008
I get the strings concatenated if i use below:

temp=23
expr $temp*60

it gives me '23*60' as output instead of the actual multiplied value.
Could you please help me out?
# 5  
Old 08-07-2008
I got it now. Thanks anyways..

it must be expr[space]$variable[space]\*[space]60

thanks
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk script to check and throw error for multiplication result

I need to multiply column1 and column3 data and need to compare it with column5. Need to check multiplication and Throw error if result is greater or less than column5 values, though difference of +/- 2 will be ok Ex - if column1 has 2.4 and column3 has 3.5, it will be ok if column5 have value... (13 Replies)
Discussion started by: as7951
13 Replies

2. Shell Programming and Scripting

IF section problem. syntax error: unexpected end of file error

Hello, I have another problem with my script. Please accept my apologies, but I am really nooby in sh scripts. I am writing it for first time. My script: returned=`tail -50 SapLogs.log | grep -i "Error"` echo $returned if ; then echo "There is no errors in the logs" fi And after... (10 Replies)
Discussion started by: jedzio
10 Replies

3. Emergency UNIX and Linux Support

Mail notifications for sudo shows syntax error

Im Using Centos Version $ cat /etc/redhat-release CentOS release 6.4 (Final) I'm Using Sudo Version $ sudo -V Sudo version 1.8.6p3 Sudoers policy plugin version 1.8.6p3 Sudoers file grammar version 42 Sudoers I/O plugin version 1.8.6p3 tried to setup notification mail for sudo,... (2 Replies)
Discussion started by: babinlonston
2 Replies

4. Hardware

Assistance required when booting M3000, error shows; * MBU_A Status:Degraded; Ver:0701h; Serial:

Here is the error showing in the XCSF, can anyone recommend further diagnosis for this specific error?; XSCF> showhardconf SPARC Enterprise M3000; + Serial:PX61142029; Operator_Panel_Switch:Locked; + Power_Supply_System:Single; SCF-ID:XSCF#0; + System_Power:On;... (4 Replies)
Discussion started by: Touchpoint
4 Replies

5. Shell Programming and Scripting

Receiving error: ./ang.ksh[35]: 0403-057 Syntax error at line 116 : `done' is not expected.

Hi All I am quite new to Unix. Following is a shell script that i have written and getting the subject mentioned error. #!/bin/ksh #------------------------------------------------------------------------- # File: ang_stdnld.ksh # # Desc: UNIX shell script to extract Store information.... (3 Replies)
Discussion started by: amitsinha
3 Replies

6. Shell Programming and Scripting

Error with "multiplication table" in shell script

#!/bin/sh echo Enter the multiplication number required: read number for i in 1 2 3 4 5 6 7 8 9 10 do echo "$number * $i = expr $number \* $i" done I am not getting the output for this multiplication table. (4 Replies)
Discussion started by: vinodpaw
4 Replies

7. Solaris

SFTP is successful but still shows timeout error

Hi, I am doing sftp from remote server1 to remote server2. This is done through a script. This script was working fine. But if i am tranfer files of 120 MB only some part of the file gets transferred (around 9 MB). Incase i put the same file manually it gets uploaded successfully. Can... (1 Reply)
Discussion started by: subiksha
1 Replies

8. AIX

nim mksysb error :/usr/bin/savevg[33]: 1016,07: syntax error

-------------------------------------------------------------------------------- Hello, help me please. I am trying to create a mksysb bakup using nim. I am geting this error, how to correct it ? : Command : failed stdout: yes stderr: no... (9 Replies)
Discussion started by: astjen
9 Replies

9. UNIX for Dummies Questions & Answers

awk Shell Script error : "Syntax Error : `Split' unexpected

hi there i write one awk script file in shell programing the code is related to dd/mm/yy to month, day year format but i get an error please can anybody help me out in this problem ?????? i give my code here including error awk ` # date-month -- convert mm/dd/yy to month day,... (2 Replies)
Discussion started by: Herry
2 Replies
Login or Register to Ask a Question

Featured Tech Videos