L
L
lekam2020-05-11 02:14:29
ubuntu
lekam, 2020-05-11 02:14:29

Why doesn't mkdir work?

I execute the command

mkdir -p /home/user/radio/audio/$(date -d"tomorrow" +%e%B)

I get a folder with tomorrow's date: /home/user/radio/audio/12мая and along the way, a non-existent audio directory is created.
Delete the audio directory, try again:
mkdir -p /home/user/radio/audio/$(date -d"4 days ago" +%e%B)

Iiiiiii I get /home/user/7маяmoreover, the audio directory appeared where it should be and it is empty.
How is that?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
U
unwrecker, 2020-05-11
@lekam

date -d"4 days ago" +%e%B

gives a space at the beginning of the line. As a result, 2 directories are created: /home/user/radio/audio/ and ./May 7

K
Karpion, 2020-05-12
@Karpion

The first thing to do in this case is to add "echo" to the beginning of the command:

echo mkdir -p /home/user/radio/audio/$(date -d"4 days ago" +%e%B)

and further thoughtfully consider what is issued there. In this case, there is an extra space.
It also makes sense to enclose the argument in quotes:
mkdir -p "/home/user/radio/audio/$(date -d"4 days ago" +%e%B)"

Inside double quotes - special characters $(...)(as well as an option for environment variables) are resolved; but spaces obtained in this way are not treated as argument separators.
In your case, this solution will result in spaces in the file name. Here you hardly need it - but consider this option.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question