cancel
Showing results for 
Search instead for 
Did you mean: 

Script problem

SOLVED
Go to solution
Paula J Frazer-Campbell
Honored Contributor

Script problem

Hi to all

I have a script wich call a script to get and use yesterdays date

from prompt
#./pastdate 1
#Jul 3 (note two spaces)

This is the output I require and this script works fine

When I call this script from my main script and echo out the result I get:-

#Jul 3 (note single space)

--------------From Script-----------
yestd=`/pastdate 1`
echo $yestD
------------------------------------

I require my output with the double space for dates less than 10 (as per std Unix date) so that I can use it to grep out credit card transaction carried out on a particular date.

So why is my date script correct when ran from the command prompt, but when it is called from within another script it presents the data with a space missing??


Help Please

Paula
If you can spell SysAdmin then you is one - anon
5 REPLIES
Pete Ellis
Trusted Contributor
Solution

Re: Script problem

Paula,

You have to put:
echo "$yestD"

to treat the variable as a single string
Satish Y
Trusted Contributor

Re: Script problem

Hi,
I can say what is the problem only if i see ur script.

But to avoid this u can insert following lines in ur script:
------------------------------------
mon=`echo $yestD | cut -d " " -f1`
day=`echo $yestD | cut -d " " -f2`
if [ $day -lt 10 ]
then
$yestD="$mon\ \ $day"
else
$yestD="$mon\ $day"
fi
-------------------------------------

Cheers...
Satish.
Difference between good and the best is only a little effort
Paula J Frazer-Campbell
Honored Contributor

Re: Script problem

Hi Pete

I use this date info as such;-

cat /avro/results |grep $yestD| awk (etc)

should this be used as:-

cat /avro/results |grep "$yestD"| awk (etc)

Paula
If you can spell SysAdmin then you is one - anon
Paula J Frazer-Campbell
Honored Contributor

Re: Script problem

Pete
Thanks that fixed it.

Paula
If you can spell SysAdmin then you is one - anon
Pete Ellis
Trusted Contributor

Re: Script problem

Paula,

That looks good to me! grep would treat look for the first word jul and think 3 was a file