Problems with expr command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Problems with expr command
# 1  
Old 01-17-2003
Problems with expr command

Hi All,

I might be making a silly mistake but I need ur help.

I have initialized various variables:
cur_month=`date +%m`
cur_year=`date +%y`
last_year=`expr $cur_year \- 1`


It works fine for cur_month & cur_year....but has problems with last_year.

FOR LAST YEAR IT GIVES A FOLLOWING MESSAGE
"expr: An integer value was expected"

Can you please help me with this.

Thanks.
RoohSmilie
# 2  
Old 01-17-2003
What shell are you using and what OS (and version)?

I tried the following on both ksh and sh on Solaris 8 - had no problem (unless I added the /- that you show - but I never got the error you have). Are you sure this is the expr command that is giving you the error? Is this a script? Can you post it?

$ cat ly
#!/bin/sh
cur_month=`date +%m`
cur_year=`date +%y`
last_year=`expr $cur_year - 1`
echo $last_year

I would also suggest you use the whole year since cur_year comes back with 03 and the subtraction gives you 2, not 02. You may mess yourself up if expecting something different.
# 3  
Old 01-17-2003
Hi RTM.

Thanks, it worked......I am using Ksh.

I used last_year=`expr $cur_year - 1` instead of last_year=`expr $cur_year \- 1` and it works fine.

Thanks alot


Rooh

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 command help

I'm trying to check if a variable'd string is only one character and use that in an if statement the only way I could find is: $expr "${var}" : . # expr STRING : regrep where the "." is the grep wildcard for any single character. Whats wrong with my code here and is there a... (3 Replies)
Discussion started by: Tewg
3 Replies

2. UNIX for Dummies Questions & Answers

substring without using expr command

Hi guys, For some reason the terminal on my mac does not let me run string manipulations commands using the expr command. I'm not sure how to fix this so I'm requesting a "work-around" to using the expr command... This is the string I'm working with: "neo_opls01_1.log" And I'm trying to... (9 Replies)
Discussion started by: ah7391
9 Replies

3. Shell Programming and Scripting

help with expr command in script

Hi, I am trying to code a unix function to calculate date difference between two date variables. I am stuck at a point where I am trying to convert hours into minutes. Below is the code I am doing. function get_elapsed_time { export PROPS_FILE=temp.properties export... (8 Replies)
Discussion started by: Nutan
8 Replies

4. Shell Programming and Scripting

expr command

Hi Can anyone explain me the usage of this command and the arguments used here and what will be the expected output : v_num=`expr nav_d_20100204_1759 : '*\(*\)'` what will be the value returned in v_num. Thanks in Advance!!! Regards Naveen Purbia (3 Replies)
Discussion started by: trying_myluck
3 Replies

5. Shell Programming and Scripting

Expr problem and other basic problems

Hello, I am new to the Bash scripting language, and was given a tutorial page on how to setup a file. However I am trying to use cygwin to run this file and it is not working. $ vi averagetime.sh # # # echo "Enter Dictorinary File Text " read dict echo "Enter Grid Name" read grid... (13 Replies)
Discussion started by: killerqb
13 Replies

6. UNIX for Dummies Questions & Answers

using the expr command

Hi friends how can i execute expr $va1 * $var2 provided i m not supposed to use '/' also the nglob variable is turned off. (4 Replies)
Discussion started by: ashishj
4 Replies

7. UNIX for Dummies Questions & Answers

problem with expr command

:) hi Unix gurus, Pls consider the following piece of code str='hello' length=echo $str|wc -c echo $length y= ` expr \( 80 - $length \) ` echo $y :confused: The last echo stmt is displaying 0 as the result. If i put direct value like 6 instead of $length in i 3rd stmt it is giving... (8 Replies)
Discussion started by: ravi raj kumar
8 Replies

8. UNIX for Dummies Questions & Answers

expr command

hi guys.... i hava a command expr... where i m adding a value in a loop like Tc=`expr $Tc\+ $l` where Tc is declred as a variable and every time l contains a new vaue if Tc =0 initially and l =2 Tc should be equal to 0+ 2 and then l = 4 Tc = 2+4 and dispaly as 6 but after... (5 Replies)
Discussion started by: madhu_aqua14
5 Replies

9. UNIX for Dummies Questions & Answers

Problems with expr

I'm writing a unix script that simply does some basic command line stuff for a whole lot of similar directories (ls *.dat > foo.bar). Its my first script ever, and its going ok, except I can't, for the life of me, figure out how to get arithmetic to work in the script. FIVE=5 MY_NUMBER='expr... (4 Replies)
Discussion started by: benu302000
4 Replies

10. UNIX for Dummies Questions & Answers

expr command

I am looking for the correct syntax on the expr command in UNIX. I have a script that I am building at the moment. the script is creating file1 that is an actual .sql file that is going inside the oracle database to get some information in there. It take that information, puts it inside another... (2 Replies)
Discussion started by: wolf
2 Replies
Login or Register to Ask a Question