date=`/usr/ucb/expr $date1 - 1`


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting date=`/usr/ucb/expr $date1 - 1`
# 1  
Old 08-09-2005
Data date=`/usr/ucb/expr $date1 - 1`

Hi I need to subtract one day from date1=`/bin/date +%d`
So I used
date=`/usr/ucb/expr $date1 - 1`

The only thing is if date1 is a single digit like 08, date will be 8 instead of 08.
How can I avoid losing 0?

Thanks for all your help!!!
# 2  
Old 08-09-2005
one way using Bourne:
Code:
echo "`date +%d` - 1`" | bc | sed 's/^.$/0&/'

Q: what will happen on the first of a month?

Last edited by vgersh99; 08-10-2005 at 11:29 AM.. Reason: correction
# 3  
Old 08-10-2005
Just a little correction to vgersh99 code
Code:
echo "`date +'%d - 1' | bc | sed 's/^.$/0&/'`"

or with 'expr' :
Code:
date1=`/bin/date +%d`
yesterday=`/usr/bin/expr $date1 - 1 | sed 's/^.$/0&/'`

Another way with KSH
Code:
typeset -Z2 yesterday
(( yesterday = $(date +%d) - 1 ))

# 4  
Old 08-10-2005
date +%d -1

Thanks a lot.
vgersh99,
I don't think there is any difference with first of the month.
I thought first of the month would be 1.

Quote:
Originally Posted by vgersh99
one way using Bourne:
Code:
echo "`date +%d) - 1` | bc | sed 's/^.$/0&/'

Q: what will happen on the first of a month?
# 5  
Old 08-10-2005
Quote:
Originally Posted by whatisthis
Thanks a lot.
vgersh99,
I don't think there is any difference with first of the month.
I thought first of the month would be 1.
$ echo '01 - 1' | bc | sed 's/^.$/0&/'
00
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. BSD

FreeBSD: /usr/bin/ld not looking in /usr/local/lib

I'm not sure if this is the default behavior for the ld command, but it does not seem to be looking in /usr/local/lib for shared libraries. I was trying to compile the latest version of Kanatest from svn. The autorgen.sh script seems to exit without too much trouble: $ ./autogen.sh checking... (2 Replies)
Discussion started by: AntumDeluge
2 Replies

2. Shell Programming and Scripting

/usr/local/bin/expr function not working

Legends, I am not able to set "expr" function in ksh script. Below is the sample code i used, and output is as "Syntax error" Please help me to come out of it. OUTPUT (9 Replies)
Discussion started by: sdosanjh
9 Replies

3. Homework & Coursework Questions

expr to translate the date command

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. Write a script called "tod" that will display the time of day in am or pm notation rather then the 24 hour clock time. Use expr to convert from 24-hour clock time. Use... (13 Replies)
Discussion started by: linuxtraining
13 Replies

4. UNIX for Advanced & Expert Users

how can i use /usr/ucb/ps to give the full user

Hi, on solaris I need the full ps output, and process this. With /usr/ucb/ps auxwww I get the output as wanted, but the user is cut off to 8 long. With ps -o ruser I can get the full username, but I do not have the full output. Is it possible to get long output, with the full username? ... (1 Reply)
Discussion started by: dimpie
1 Replies

5. Solaris

How do I link ld in /usr/ucb/ to /usr/ccs/bin?

Hi all, below is the problem details: ora10g@CNORACLE1>which ld /usr/ucb/ld ora10g@CNORACLE1>cd /usr/ccs/bin ora10g@CNORACLE1>ln -s /usr/ucb/ld ld ln: cannot create ld: File exists ora10g@CNORACLE1> how to link it to /usr/ccs/bin? (6 Replies)
Discussion started by: SmartAntz
6 Replies

6. Shell Programming and Scripting

long process listing with /usr/ucb/ps weird behaves

hello I am trying to run the following script to get the my-progam pid: #!/bin/ksh tt=`/usr/ucb/ps| grep -i $1| grep -v grep | awk '{print $2}'` echo $tt When I run the script I get the more PIDs $./test.sh my-program 12033 15033 15034 Actually my-program's PID is 12033....I... (6 Replies)
Discussion started by: sreeniatbp
6 Replies

7. UNIX for Advanced & Expert Users

/usr/ucb/ps -auxwll

Hei, When I run the /usr/ucb/ps -auxwll with any other user except root I get nothing (Solaris 10 in global). Is a way to get the same resualt as root with my user. tnx Mehrdad (0 Replies)
Discussion started by: mehrdad68
0 Replies

8. Shell Programming and Scripting

problem get the value of /usr/ucb/ps -guxww

Hello all im trying to get the value of: /usr/ucb/ps -guxww | grep Tomcat | grep $USER | grep -v grepinto variable , im using csh . like this : set PS="/usr/ucb/ps -guxww" set isTomcat = `cat $PS | grep Tomcat | grep $USER | grep -v grep` but im keep geting this error: cat: cannot open... (4 Replies)
Discussion started by: umen
4 Replies

9. Solaris

/usr/bin/ps -p equivalent in ucb version

Hi, Is there an option in /usr/ucb/ps version to get a selected list of processes like in /usr/bin/ps -p"1 3 5" option? Thanks, Fredy (7 Replies)
Discussion started by: fredy
7 Replies

10. Solaris

solaris 2.5.1 /usr/ucb/ps truncation problems

we aheva couple of old sun OS boxes, that we are trying to parse /usr/ucb/ps output. However it seems that something is occuring that is causeing th output of "/usr/ucb/ps -auxwww" to cut short the process name, whereas "ps -eaf" can display the entire process name. It will work for a while... (2 Replies)
Discussion started by: adralph
2 Replies
Login or Register to Ask a Question