[PLUG] "date" output cli/bash inconsistency

Kyle Accardi sandbox at pacifier.com
Sat Aug 2 19:32:02 UTC 2003


Steven Raymond wrote:
> Can someone please explain why the same command executed from the command
> line vs. in a bash script, would output differently:
> 
> [root at sparky log]# echo $SHELL
> /bin/bash
> [root at sparky log]# cat rejectmail.sh
> #!/bin/bash
> TODAY=`date -d "8/1/2003" "+%b %e"`
> echo $TODAY
> 
> [root at sparky log]# ./rejectmail.sh
> Aug 1
> [root at sparky log]# date -d "8/1/2003" "+%b %e"
> Aug  1
> [root at sparky log]#
> 
> 
> Note I want the latter output, "Aug  1" (note with two spaces).  The %e
> switch with date command does exactly what I want from the command line,
> but acts differently when run from a script.  Why is that?  Apparently
> enclosing the command in `` makes it act differently.
> 


Echo strips out extra spaces, enclose the variable in quotes

echo "$TODAY"

--
Kyle Accardi





More information about the PLUG mailing list