Bash variable delayed expansion?

i write a batch file , here is the content.

dirname='date +%Y-%m-%d'
mkdir dirname

but it doen's work, it just create a folder named date and +%Y-%m-%d.
i have tried run the command seperately in the bash prompt. after the first
sentence executed , i use $dirname to watch the value of dirname ,it's right.
but how come mkdir command doesn't work?

zra:/home/vbe $ dirname=$(date +%Y-%m-%d)
zra:/home/vbe $ echo $dirname            
2010-07-09

so

mkdir $dirname

after...

How about ...

mkdir $dirname

... or "simply" ...

mkdir $( date '+%Y-%m-%d' )
  1. To use the output of a command, use $(), or the older backticks `. Regular quotes won't work.
  2. Variables are used by prefixing them with a dollar symbol
1 Like

thanks Mr. vbe and dr.House, i had a typo in my previous post, i do use 'mkdir $dirname'.

hi, pludi, your way works, thanks very much .