Results 1 to 4 of 4
I have a problem with command line .sh scripting. I can not rewrite this in any other language, but I need to do a check when the script kicks off ...
- 02-16-2009 #1Just Joined!
- Join Date
- Feb 2009
- Posts
- 1
Command line date
I have a problem with command line .sh scripting. I can not rewrite this in any other language, but I need to do a check when the script kicks off to see if the date is entered on the command line and if not, use yesterday. Here is what I have so far:
if [ $# -eq 0 ]; then
TODAY=`/usr/local/bin/cprevdate -f %m/%d/%Y`;
echo "$# is zero "
else
TODAY= $1
echo $1
fi
print "Today is $TODAY ";
exit;
I can do this in any other language, but I have never used .sh for this type of command. Please please someone, tell me what I can do to fix this!
- 02-16-2009 #2Linux Guru
- Join Date
- Nov 2007
- Posts
- 1,695
Google > calculate date linux
Code:datecalc -a 1960 12 31 - 1
- 02-17-2009 #3Linux User
- Join Date
- May 2008
- Location
- NYC, moved from KS & MO
- Posts
- 251
Quick solution:
Slow but better solution:Code:#!/bin/bash [ $# -eq 0 ] && TODAY=`date -d "yesterday" "+%m/%d/%Y"` || TODAY=$1 echo "Today is $TODAY"
man date
- 02-17-2009 #4Linux Guru
- Join Date
- Nov 2007
- Posts
- 1,695
Nice.
And => LinuxForums Search


Reply With Quote
