expr error in ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting expr error in ksh
# 1  
Old 10-19-2008
expr error in ksh

Hi ALL,

i am so much confused y the following script is not working in the korn shel which works in bash shell. please solve the error that i am facing.

i want to extract the format of the size from a variable i.e. GB or KB or MB or B or BYTES

code:
--------
size_dir_pass=1.2gb
size1=`expr $size_dir_pass | sed 's/[\.0-9]//g'`
echo "size1" $size1

size1 value is not printing ... please help me ...

Error :
Usage : expr expression

Thanks in advance
kamal
# 2  
Old 10-19-2008
I am not facing any problem in Korn shell
Code:
> size_dir_pass=1.2gb
> size1=`expr $size_dir_pass | sed 's/[\.0-9]//g'`
> echo "size1" $size1
size1 gb
> echo $SHELL
/bin/ksh

# 3  
Old 10-19-2008
I don't see why "expr" is there at all; and it won't understand suffixes.
Code:
$ size_dir_pass=1.2gb
$ size1=${size_dir_pass##*[0-9.]}
$ echo $size1
gb


Last edited by geekosaur; 10-19-2008 at 02:12 PM.. Reason: no markup. grmbl.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

2. Shell Programming and Scripting

Expr Syntex error

Hello, I am new to Shell programing. I want to add two numbers & show result. command I use are as under Echo Enter the two numbers read number d1 = ` expr $ num%10` num = `expr $ num/10` d2 = ` expr $ num%10` num = `expr $ num/10` sum = $ d1 + $ d2 echo the sum is $ sum I am getting... (1 Reply)
Discussion started by: pbchhaya
1 Replies

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

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

5. Shell Programming and Scripting

Error extracting 1 or more numbers with expr command

Need help with the following, I want to extract the digits from the following file pattern using the expr command. digits are in the range 1-99 Tried two different methods, not sure what I am doing wrong. file1=file1.dbf file10=file10.dbf Works for expr "$file10" : '.*\(\)' 10 ... (2 Replies)
Discussion started by: fire!
2 Replies

6. Shell Programming and Scripting

expr inside a ksh script Solaris

Hi; If I do something like this. dftotalsize=0;export dftotalsize;df -k | grep \/db001 | awk '{print $4}' | while read theinput \ ; do export $theinput; dftotalsize=`expr $dftotalsize + $theinput`; export dftotalsize; echo $dftotalsize; done ; echo `expr $dftotalsize \/ 1024 \/ 1024 "GB" Is... (4 Replies)
Discussion started by: myjess
4 Replies

7. Shell Programming and Scripting

ksh script using expr to calculate percentages

Within a ksh script on HP-UX I trying to calculate a percentage of a number (number/100 x percentage) using the below method and expr. TARPERC=`expr 16 / 100 \* 5` TARSUM=`expr 16 + $TARPERC` ZIPSUM=`expr $TARSUM \* 2` If the input is 16 outputs are: TARPERC: 0 TARSUM: 16 ZIPSUM: 32... (6 Replies)
Discussion started by: wurzul
6 Replies

8. Shell Programming and Scripting

getting error with expr

sum=0; cat op_api2 |while read word1 word2; do echo $word2 sum=`expr $word2 + $sum`; done echo $sum op_api2 ( file has this data ) ---------------------------- UsageSummary 1034 UsageSummary 1675 UnbilledUsage 175 UnbilledUsage 177 UnbilledUsage 177 UnbilledUsage 194 I want the... (2 Replies)
Discussion started by: bishweshwar
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. UNIX for Advanced & Expert Users

how do I get the value of expr with ksh

Hi, I have written a korn shell script to compute the value of k. formulae : a=10 b=20 c=30 k=(a+b)*c my shell script is : a=10 b=20 c=30 k=`expr (($a + $b ) * $c )` echo $k ### here paranthesis ( ) not accepting by expr function. (3 Replies)
Discussion started by: krishna
3 Replies
Login or Register to Ask a Question