Reputation: 1193
I try to create folder in my server with the current date.
So I wrote the next lines:
$ mkdir # date +”%d-%m-%Y”
cd # date +”%d-%m-%Y”
and save it as .sh
, But for somme reasom it doesn't work. What can be the reason?
Upvotes: 6
Views: 19555
Reputation: 5218
You should use
mkdir "$(date +"%d-%m-%Y")"
cd "$(date +"%d-%m-%Y")"
In the extreme case a day passes between the first and the second statement, that won't work. Change it to:
d="$(date +"%d-%m-%Y")"
mkdir "$d"
cd "$d"
Explanation: The $(...)
returns the output from the subcommands as a string, which we store in the variable d
.
(Quoted the variables as suggested by tripleee)
Upvotes: 18