Results 1 to 6 of 6

Thread: mkdir issue

  1. #1

    Default 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?

  2. #2

    Default Re: mkdir issue

    Quote Originally Posted by abacabb View Post
    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
    Code:
    05-10-2011- 726
    Because you use %l (= hour 1..12). The %l does not provide leading zeros.

    You should use %I instead:
    Code:
    mkdir $(date +%m-%d-%Y-%I%M%p)
    You can test the output easily with
    Code:
    echo $(date +%m-%d-%Y-%I%M%p)

  3. #3
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: mkdir issue

    Or just run:

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

  4. #4

    Default Re: mkdir issue

    Quote Originally Posted by ken_yap View Post
    Or just run:

    date +%m-%d-%Y-%I%M%p
    Yes... of course

  5. #5

    Default Re: mkdir issue

    Thanks Ken! You are the man.

  6. #6
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: mkdir issue

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •