Search code examples
bashmkdirtildetilde-expansion

Cannot create directory with tilde


Given this script

# cat foo.sh
echo $HOME
set -x
mkdir ~

I am getting this result

# ./foo.sh
/home/Steven Penny
++ mkdir ''
mkdir: cannot create directory `': No such file or directory

If I run mkdir "$HOME" I have no problem. I think the issue is the space in the path, but can someone shed some light on this?


Solution

  • The problem was that the /etc/passwd file was missing.

    To elaborate, even one this simple will work

    Steven Penny::0:0::/home/Steven Penny