expr: non-numeric argument


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting expr: non-numeric argument
# 1  
Old 07-14-2010
expr: non-numeric argument

Hi all,

i am facing the error "expr: non-numeric argument" when i use the expr command.

Following is the expression which i want to execute

Code:
HR=$(echo `date +%H`)
MIN=$(echo `date +%M`)
TOT_MIN=`expr "$HR" \* 60+$MIN` | bc
echo $TOT_MIN

Here I am being reported with the error expr: non-numeric argument.
when i use bc i get the standard parse error. Smilie
Please help me how to get rid of these errors.

Thanks in advance!!! Smilie

Last edited by pludi; 07-14-2010 at 06:33 AM..
# 2  
Old 07-14-2010
Code:
HR=$(echo `date +%H`)
MIN=$(echo `date +%M`)
TOT_MIN=`expr "$HR" \* 60 + $MIN | bc`
echo $TOT_MIN

# 3  
Old 07-14-2010
The closing backtick must be at the end of the line. Replace this:
Code:
TOT_MIN=`expr "$HR" \* 60+$MIN` | bc

with:
Code:
TOT_MIN=`expr $HR \* 60 + $MIN | bc`

# 4  
Old 07-14-2010
Quote:
Originally Posted by Franklin52
The closing backtick must be at the end of the line
Not if you do this (as I just did by accident!)

Code:
TOT_MIN=`expr "$HR \* 60+$MIN` | bc

There's no floating point stuff here, so I would get rid of bc and expr:

Code:
TOT_MIN=$(($HR * 60 + $MIN))

# 5  
Old 07-14-2010
typeset is also an alternative,

Code:
typeset -i HR MIN TOT_MIN
HR=$(date +%H)
MIN=$(date +%M)
TOT_MIN=$HR*60+$MIN

# 6  
Old 07-14-2010
Quote:
Originally Posted by scottn
Not if you do this (as I just did by accident!)

Code:
TOT_MIN=`expr "$HR \* 60+$MIN` | bc

There's no floating point stuff here, so I would get rid of bc and expr:

Code:
TOT_MIN=$(($HR * 60 + $MIN))

Good point, Thanks!
# 7  
Old 07-14-2010
Thanks everybody.. It helped Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Expr: non-numeric argument syntax error on line 1, teletype

Hi, I tried to look up the issue i'm experiencing, but i'm confused what's wrong with my script. After executing the script I'm getting the following error expr: non-numeric argument syntax error on line 1, teletype After some research, it seems that the problem relates to bc. I have... (1 Reply)
Discussion started by: nms
1 Replies

2. Shell Programming and Scripting

Expr: non-integer argument

This is my code.... It works correct, but does not work with 4 and 5. My program is about finding average. so when i run 4 5 it gives me error "expr: non-integer argument". But when i say sh average 45 67 it works. Whats wrong?how to fix it? sum=0 n=0 if then for i in $* do if ... (2 Replies)
Discussion started by: Natalie
2 Replies

3. Shell Programming and Scripting

Non-integer argument in expr

i wrote this simple shell script #!/bin/bash read N1 read N2 expr $N1 + $N2 it work fine in bash and i add it on xinetd for some test but when i try to use in with telnet i got this error : ehsan@debian:~$ telnet 192.168.1.4 1234 Trying 192.168.1.4... Connected to 192.168.1.4.... (14 Replies)
Discussion started by: niasha
14 Replies

4. Shell Programming and Scripting

Numeric argument required

Hi, How to return the string "y" to the calling function. Getting the below error when function returns the value. return: y: numeric argument required With Regards (2 Replies)
Discussion started by: milink
2 Replies

5. Shell Programming and Scripting

Korn expr substr fails for non-numeric value

I am running AIX 5.3 using the Korn Shell. I am reading file names from a file, as an example: E0801260 E0824349 E0925345 EMPMSTR statement "num=$(expr substr "$DDNAME" 4 2) extracts the numeric values fine. But when I het the last entry, it returns num=MS, but I get an error... (19 Replies)
Discussion started by: kafkaf55
19 Replies

6. Shell Programming and Scripting

expr: Integer argument too large

Hi all, In KSH, I have got an error message like, "expr: Integer argument too large" I received this error message when I mutiply two large values and displaying the resultant output. Is there any other altenative way to go with too large values? Kindly let me know asap... Thanks in... (12 Replies)
Discussion started by: iamgeethuj
12 Replies

7. UNIX for Dummies Questions & Answers

First argument is numeric or not

Hi everyone, I want my script to check if the first argument has only numbers or not. Im not sure what im doing wrong. This is how it looks like: if *") ] then echo 'The first arguement should only be in numeric' 1>&2 exit 1 else exit 0 fi (7 Replies)
Discussion started by: darkhider
7 Replies

8. UNIX for Dummies Questions & Answers

Non Numeric Argument Error

hi there, I was recently introduced to this site by a friend. I hope you guys can help with a code error i can't seem to debug.I can get to add two different data types together. A snippet of the code is below: echo -n "Enter Your MOnthly Investment" read Inv PIP= $(echo "scale=2; 10 / 100"... (4 Replies)
Discussion started by: Allenzo
4 Replies

9. UNIX for Dummies Questions & Answers

non-numeric argument

quick question, I am trying to run this simple equation expr 2048 / 2.354 but get a "expr: non-numeric argument" error when ever its run. I believe it may be caused by the decimal point but I do not know how to remedy it. (3 Replies)
Discussion started by: TiredOrangeCat
3 Replies

10. Shell Programming and Scripting

expr+float argument: how can i do?

Hi everybody, I want to know how can i use the command 'expr' to manipulate float number , i have a shell bash and when (for example) i do: y1=`expr \( 1/ 16 \)` it returns 0 and if i do y1=`expr \( 1.6 / 16 \)` it returns non numeric argument. is there another command for mathematic... (4 Replies)
Discussion started by: mips
4 Replies
Login or Register to Ask a Question