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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Expr: non-numeric argument syntax error on line 1, teletype
# 1  
Old 10-31-2017
Wrench 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

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

After some research, it seems that the problem relates to bc.
I have the following part from the script:

Code:
FREE=`df -g $i | grep files | awk '{print$1}' | tail -1`
TOTAL=`df -g $i | grep files | awk '{print$9}' | head -1`
USED=`expr $TOTAL - $FREE`
USED_PER=`echo "scale = 5; ($USED / $TOTAL)*100" | bc`
USED_PER=`printf %0.f $USED_PER`
OUTPUT=`echo $DATE "|" $i "|" $USED_PER`

and changed the above to the below, however issue is still persisting. While performing bash -x, i noticed that all values are being retrieved, but noticed that some values are negative or float.

Code:
FREE=$(df -g $i | grep files | awk '{print$1}' | tail -1)
TOTAL=$(df -g $i | grep files | awk '{print$9}' | head -1)
USED=$(expr $TOTAL - $FREE)
USED_PER=$(echo "scale = 5; ($USED / ($TOTAL))*100" | /usr/bin/bc)
USED_PER=`printf %0.f $USED_PER`
OUTPUT=`echo $DATE "|" $i "|" $USED_PER`

Can someone shed some light on what could be the problem?

Last edited by Scott; 10-31-2017 at 09:46 AM.. Reason: Use code tags, please...
# 2  
Old 10-31-2017
Quote:
Originally Posted by nms
Code:
expr: non-numeric argument
syntax error on line 1, teletype

Code:
USED=`expr $TOTAL - $FREE`

expr expects that $TOTAL and $FREE would be a numeric argument. You do not check before hand that that's what they have before using it.

Quote:
Originally Posted by nms
and changed the above to the below, however issue is still persisting. While performing bash -x, i noticed that all values are being retrieved, but noticed that some values are negative or float.

Code:
FREE=$(df -g $i | grep files | awk '{print$1}' | tail -1)
TOTAL=$(df -g $i | grep files | awk '{print$9}' | head -1)
USED=$(expr $TOTAL - $FREE)
USED_PER=$(echo "scale = 5; ($USED / ($TOTAL))*100" | /usr/bin/bc)
USED_PER=`printf %0.f $USED_PER`
OUTPUT=`echo $DATE "|" $i "|" $USED_PER`

Can someone shed some light on what could be the problem?
From man bc in my system.
Code:
There are two attributes of numbers, the length and the scale.  The length is the total number of significant decimal digits in a num-
       ber and the scale is the total number of decimal digits after the decimal point.  For example:
               .000001 has a length of 6 and scale of 6.
               1935.000 has a length of 7 and a scale of 3.

You are using old shell scripting syntax. If you had posted what OS and shell type you are using more could had been said about those.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem with syntax error on line 1, teletype

Hi All, I am getting below error message while executing memory utilization script. $ ./mem1.sh syntax error on line 1, teletype syntax error on line 1, teletype $ $ uname -a SunOS 5.9 XXX Generic_122300-60 sun4u sparc SUNW,Sun-Fire-V440 $ But i can execute same script in... (3 Replies)
Discussion started by: susindram
3 Replies

2. Shell Programming and Scripting

Error with expr - "expr: syntax error"

Hi All, I'm writing a shell script in KSH, where I want to store the filename, total record count and actual record count of all the source files. The source files reside in 4 different sub-folders under the same root folder. Below is code: #!/usr/bin/ksh... (6 Replies)
Discussion started by: jagari
6 Replies

3. Shell Programming and Scripting

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 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:... (6 Replies)
Discussion started by: sparks
6 Replies

4. UNIX for Dummies Questions & Answers

expr: syntax error

Hi All, This is a piece of code from one of my scripts: t1=`cat temp3.21447 | grep WEALTHTOUC_TRANS_20100409_233127.txt.txt.TRG | awk '{print $3}' | cut -c1-5` t2=`cat temp3.21447 | grep WEALTHTOUC_TRANS_20100409_233127.txt.txt.TRG | awk '{print $5}' | cut -c1-5` #t1=23:43... (5 Replies)
Discussion started by: prachiagra
5 Replies

5. UNIX for Dummies Questions & Answers

expr - Syntax error

hello to everyone, i am writing a shell script in unix and i use the following command: lnum= cut -f 1 -d : aa passline=`expr $lnum + 1` echo "$passline" with the following command i get the value that is stored in the first field of the file "aa" and i save it in the variable "lnum". i am... (2 Replies)
Discussion started by: omonoiatis9
2 Replies

6. 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

7. 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

8. UNIX for Advanced & Expert Users

I got error like...syntax error on line 1, teletype

Hi All, when i executing scripts i got error like: syntax error on line 1, teletype expr: syntax error expr: syntax error expr: syntax error Please advise to me. Note: Yesterday it's working fine, 2day only i got error. (2 Replies)
Discussion started by: koti_rama
2 Replies

9. Shell Programming and Scripting

expr: syntax error. why?

i want to get a substring from a string and used such shell script: var_year=`expr substr "07132006" 5 4` echo $var_year but i got such error message: expr: syntax error. why? Note: Kshell used on solaris 8. :confused: (5 Replies)
Discussion started by: robin.zhu
5 Replies

10. Shell Programming and Scripting

syntax error on line 1, teletype

Hi There, I have a cron script that returns the error: syntax error on line 1, teletype Has any one seen this, know what it is, or know's how to get rid of it? Thanks, Jeremy. (1 Reply)
Discussion started by: KokoPops
1 Replies
Login or Register to Ask a Question