This is probably archaic, but I'm new to unix and this is my first shell script. I'm writing this script to use in another script. All I am trying to do is make the parts of the output from date usable in my other script. I was wondering if you could stand looking at this and see if you notice why I can't get my last line to execute.
#! /bin/sh
wday=`date | head -c +3`
echo "$wday"
cyear=`date | tail -c -5`
echo "$cyear"
ahour=`date | head -c +13 | tail -c +12 -`
if [$ahour - 12 -ge 0]
then
thour=`expr $ahour - 12`
x=`PM`
else
thour=`12 - $ahour`
x=`AM`
fi
if [$wday == Mon]
then
wday= 'Monday'
else
if [$wday == Tue]
then
wday= 'Tuesday'
else
if [$wday == Wed]
then
wday= 'Wednesday'
else
if [$wday == Thu]
then
wday= 'Thursday'
else
if [$wday == Fri]
then
wday= 'Friday'
else
if [$wday == Sat]
then
wday= 'Saturday'
else
if [$wday == Sun]
then
wday= 'Sunday'
fi
echo "$wday"
echo "The time is $thour $x."
exit 0
Thank you, that works very well. But I can't just grab the day of the week out as a variable. I also can't grab the year. I am trying to use my script to make the data available. Some of the commands (as the one you made so simple) are just there for troubleshooting.
Thanks, that works perfectly. Care to explain how that statement works? Can you use that sort of statement to parse any data or just the date statement?
You can use it with most things when you have to pass something to the standard input of, for example your read statement, or another program or a script, etc.