Cannot create directory with tilde

981 views Asked by At

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?

2

There are 2 answers

0
Zombo On BEST ANSWER

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
0
Kannan Mohan On

Looking at your debug output

++ mkdir ''

looks like "~" in mkdir ~ is expanding to nothing, thus causing mkdir to fail. As mkdir $HOME works fine it means you have enough space in the disk.

Can you check if echo ~ is displaying your home directory.