2

Why does the following command: mkdir -p '~/something' creates a directory directory named as '~' in the current, instead of creating a directory named as something in the home directory? Is there any way to fix this?

ps. I get the value ~/something as an environment variable wrapped in single quotation.

Gandalf
  • 346

1 Answers1

4

Inside single or double quotes, ~ is managed literally as a tilde character, it is not translated to "current-user-home-folder".

You have two alternative ways to achieve your target:

  • using double quotes and replacing the tilde symbol with the variable $HOME. Summarizing: mkdir -p "$HOME/something". The $, opposite to ~, is not treated as a literal inside double quotes.
  • just not quoting the tilde. Summarizing: mkdir -p ~/'something'
Lorenz Keel
  • 9,511