Keeping padding in a date field

Hi Guys,

I'm having a bit of a problem with a script, i need to get the day, month and day of month into a string, so i'm using:

CURRENT_DATE=`date +"%a %b %e"`

It is getting the correct date out, however it is not keeping the padding on the day of month. The %e is supposed to pad the day of month, but it doesn't seem to want to.

What should be coming out is 'Fri Jan 9' (2 spaces padding before the 9), but it is giving me 'Fri Jan 9' (one space :mad:)

If i use the command 'date' in the unix shell it brings it in the right format, however if i use 'echo `date`' it removes the padding on the day of the month.

This is probably a very confusing post, i apologise!! Really hope someone can help :confused:

Just quote the identifier:

bash-3.2.48(21)[~]$ CURRENT_DATE="$(date +"%a %b %e")"
bash-3.2.48(21)[~]$ echo $CURRENT_DATE 
Fri Jan 9
bash-3.2.48(21)[~]$ echo "$CURRENT_DATE"
Fri Jan  9

Why not use:

# date +"%a %b %d"
Fri Jan 09

It keeps 2 digit date.

%e does pad on my RedHat box:

# date +"%a %b %e"
Fri Jan  9

EDIT:
Ahh I get it now.. Just do what radoulov says....

Thanks for your help guys!

Still having a problem though, i'm plugging the variable into a sed command and its still not padding the %e variable:

CURRENT_DATE="$(date +"%a %b %e")"

sed -n '/^"$CURRENT_DATE"/,$ p' /var/sean/errorlog.log > /tmp/tempfile.tmp

Again, any help is appreciated!

You are not plugging the variable into the sed command; you are giving it a literal string because it is within single quotes.

CURRENT_DATE=$(date +"%a %b %e")
sed -n "/^$CURRENT_DATE/,$ p" /var/sean/errorlog.log > /tmp/tempfile.tmp

Ah rite. Solves the problem, thanks dude!