system mkdir

Steven Schveighoffer schveiguy at
Thu Mar 18 06:38:07 PDT 2010

On Thu, 18 Mar 2010 09:28:06 -0400, noboy <nobody at> wrote:

> I was little bit surprise because
> mkdir -p dmd-2/usr/{bin,lib,src/phobos2,share/man
> do the right thing.

When you do that, you are using your shell.  The shell actually does the  
argument expansion, not mkdir.  So the question to answer is, does system  
use the shell or just call mkdir directly.  According to my man page,  
using system("cmd") is equivalent to doing /bin/sh -c cmd.  On my system  
doing this:

/bin/sh -c 'mkdir -p /testdir/{a,b,c}'

results in the desired behavior.  The single quotes force the shell I'm  
currently running *not* to expand the arguments, but pass them directly to  
/bin/sh as one string.  I would expect that system would execute the same  

I would guess on my system that your code would work properly, but I'm not  
sure.  What you need to find out is what /bin/sh actually is on your  
system.  Maybe it is a shell that does not understand how to expand the  
{a,b,c} term.  IIRC, /bin/sh usually is a link to bash, but I think on  
some systems, bash behaves differently if it's called via /bin/sh.

> But if i make
> mkdir -p "dmd-2/usr/{bin,lib,src/phobos2,share/man"
> it's wrong.
> So i have think the system command wrap quotes about the command.

I don't think this is what's happening.


More information about the Digitalmars-d-learn mailing list