The Computer Oracle

How to create a directory named '-p' under Linux with Bash?

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Fantascape Looping

--

Chapters
00:00 How To Create A Directory Named '-P' Under Linux With Bash?
00:22 Answer 1 Score 17
00:33 Accepted Answer Score 39
00:58 Thank you

--

Full question
https://superuser.com/questions/738583/h...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#linux #bash

#avk47



ACCEPTED ANSWER

Score 39


Most utilities (all POSIX compliant ones except for test and echo) support an "end of options" option --, so you could run:

mkdir -- -p

This is especially useful when renaming or removing files that could potentially start with a dash. In scripts you should always use

mv -- "$filename"

instead of a plain mv "$filename" or, even worse, an unquoted filename.




ANSWER 2

Score 17


mkdir ./-p

Keep in mind that most other programs would need to use the same "trick".