Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am trying to create a directory with a timestamp. If I type at the prompt

mkdir "$(date +%Y-%m-%d_%H%M%S)"

I get a directory named with the date as I would like. If I put the same line in a bash script I get some strange characters at the end of the name. What is going on? I am attempting this in Cygwin and tried bash and sh.

share|improve this question
4  
Can you post an actual script and the actual output you get? –  Paul Griffiths Jul 17 '14 at 20:18
1  
It's probably your $PATH and/or shell builtins/functions/aliases. Verify that command -V date and ENV=/dev/fd/0 sh <<< 'command -V date' produce the same output. –  mikeserv Jul 17 '14 at 21:01
1  
Or... And I should have noticed this before... You should definitely be quoting the +... bit like "$(date '+%Y-%m-%d_%H%M%S')" - though I'm not certain off the top of my head why that would behave differently in a script than at the prompt. –  mikeserv Jul 17 '14 at 21:08
    
Check your LC_TIME –  tijagi Jul 18 '14 at 0:37

1 Answer 1

I had same problem with Cygwin. You need to run

dos2unix mkdatedir.sh  # or whatever your script is called

this will remove any dos carriage returns

but better to set option igncr

see https://cygwin.com/ml/cygwin-announce/2010-08/msg00015.html

share|improve this answer
    
Ahh, very good. This makes perfect sense. –  mikeserv Jul 19 '14 at 4:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.