mkdir issue

For some reason when I execute the following command:

mkdir $(date +%m-%d-%Y-%l%M%p)

…it create 2 directories. One with today’s date plus a dash at the end, and another directory which is using the time as it’s name. So lets say if on april 1st, 2011 at 1:14PM I execute that command, it will create a directory called “04-01-2011-” and another directory called 114PM.

My goal was to have it create only one directory named “04-01-2011-114PM”

any ideas?

The 2 directories come from the space in

05-10-2011- 726

Because you use %l (= hour 1…12). The %l does not provide leading zeros.

You should use %I instead:

mkdir $(date +%m-%d-%Y-%I%M%p)

You can test the output easily with

echo $(date +%m-%d-%Y-%I%M%p)

Or just run:

date +%m-%d-%Y-%I%M%p

lol! Yes… of course

Thanks Ken! You are the man.

Just to add, if you really wanted to create a directory with a space in the name, what you have to do is double quote the entire argument.

mkdir “$(date +%m-%d-%Y-%l%M%p)”

Just to illustrate a point about what constitutes a single argument.