[PLUG] how to adjust for special characters in mkdir() function?

logical american website.reader3 at gmail.com
Sat Oct 2 04:13:11 UTC 2010


> daniel at krosp:~$ ls -ld '/tmp/foo bar'
> ls: cannot access /tmp/foo bar: No such file or directory
> daniel at krosp:~$ perl -e 'mkdir("/tmp/foo bar/baz quux", 0777) or die $!'
> No such file or directory at -e line 1.
> daniel at krosp:~$ mkdir /tmp/'foo bar'
> daniel at krosp:~$ perl -e 'mkdir("/tmp/foo bar/baz quux", 0777) or die $!'
> daniel at krosp:~$ ls -ld '/tmp/foo bar'{,/*}
> drwxrwxr-x 3 daniel daniel 21 Oct  2 13:50 /tmp/foo bar
> drwxrwxr-x 2 daniel daniel  6 Oct  2 13:50 /tmp/foo bar/baz quux
>
> mkdir(2) and mkdir(3) (and related tools like mkdirat) will only create the
> specific target directory, not any part of the path, as was mentioned.
>
> Also, if that didn't work ... well, it would have been noticed. :)
>
>> http://linux.die.net/man/3/mkdir mkdir() only takes two parameters and I'm
>> not sure how it handles spaces in the parameter #1.
> The same way any path handling function under Unix / POSIX does: they are
> treated exactly the same as any other legal character for a file naming
> component, which is to say like any character except for NUL and '/'.
>
> Regards,
>          Daniel
Ironically mkdir -p does create a full path directory with multiple 
slashes, I am using it right now in a shell script program.  But 
apparently mkdir() won't




More information about the PLUG mailing list