digitalmars.D.learn - system mkdir
- noboy (17/17) Mar 18 2010 Hello,
- Steven Schveighoffer (6/24) Mar 18 2010 The system function calls the libc system function. If you don't like t...
- noboy (10/45) Mar 18 2010 I was little bit surprise because
- Steven Schveighoffer (18/25) Mar 18 2010 When you do that, you are using your shell. The shell actually does the...
- noboy (4/38) Mar 18 2010 There was a soft link /bin/sh -> dash
- Spacen Jasset (5/45) Mar 19 2010 then presumably the syntax you are using is a bashism?. You could also
- Jesse Phillips (6/10) Mar 19 2010 Actually, not messing with it will have undesired consequences. Lots of
- noboy (6/23) Mar 20 2010 Yes this can be true. In April i start an update from Kubuntu 8.04 LTS ...
- Jesse Phillips (2/7) Mar 24 2010 Totally missed this. Yeah the problem got me thinking about how I use sy...
Hello, import std.stdio; import std.process; import std.string; void main() { string debPackage="dmd-2"; int dmdVersion=2; auto path = format("%s/usr/{bin,lib,src/phobos%d,share/man}",debPackage,dmdVersion); system("mkdir -p " ~ path); } The result: dmd-2/usr/{bin,lib,src it should be dmd-2/usr/bin dmd-2/usr/lib dmd-2/usr/src Kubuntu 8.0.4
Mar 18 2010
On Thu, 18 Mar 2010 06:25:20 -0400, noboy <nobody nowhere.com> wrote:Hello, import std.stdio; import std.process; import std.string; void main() { string debPackage="dmd-2"; int dmdVersion=2; auto path = format("%s/usr/{bin,lib,src/phobos%d,share/man}",debPackage,dmdVersion); system("mkdir -p " ~ path); } The result: dmd-2/usr/{bin,lib,src it should be dmd-2/usr/bin dmd-2/usr/lib dmd-2/usr/src Kubuntu 8.0.4The system function calls the libc system function. If you don't like the behavior, complain to the developers of libc for Kubuntu. If system is behaving differently under C, then that might be D's problem, but I can't tell if that's the case from your example. -Steve
Mar 18 2010
I was little bit surprise because mkdir -p dmd-2/usr/{bin,lib,src/phobos2,share/man do the right thing. 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. Perl have the same behaviour. Thank you for your answer. Steven Schveighoffer Wrote:On Thu, 18 Mar 2010 06:25:20 -0400, noboy <nobody nowhere.com> wrote:Hello, import std.stdio; import std.process; import std.string; void main() { string debPackage="dmd-2"; int dmdVersion=2; auto path = format("%s/usr/{bin,lib,src/phobos%d,share/man}",debPackage,dmdVersion); system("mkdir -p " ~ path); } The result: dmd-2/usr/{bin,lib,src it should be dmd-2/usr/bin dmd-2/usr/lib dmd-2/usr/src Kubuntu 8.0.4The system function calls the libc system function. If you don't like the behavior, complain to the developers of libc for Kubuntu. If system is behaving differently under C, then that might be D's problem, but I can't tell if that's the case from your example. -Steve
Mar 18 2010
On Thu, 18 Mar 2010 09:28:06 -0400, noboy <nobody nowhere.com> 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 command. 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. -Steve
Mar 18 2010
There was a soft link /bin/sh -> dash I have change this to bash, and now all went fine. Thank you Steven Schveighoffer Wrote:On Thu, 18 Mar 2010 09:28:06 -0400, noboy <nobody nowhere.com> 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 command. 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. -Steve
Mar 18 2010
noboy wrote:There was a soft link /bin/sh -> dash I have change this to bash, and now all went fine. Thank you Steven Schveighoffer Wrote:then presumably the syntax you are using is a bashism?. You could also say something like: system("bash mkdir -p " ~ path); Messing with your sh symlink may have some undesired consequences.On Thu, 18 Mar 2010 09:28:06 -0400, noboy <nobody nowhere.com> 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 command. 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. -Steve
Mar 19 2010
Spacen Jasset wrote:then presumably the syntax you are using is a bashism?. You could also say something like: system("bash mkdir -p " ~ path); Messing with your sh symlink may have some undesired consequences.Actually, not messing with it will have undesired consequences. Lots of scripts assume sh points to bash. Though he should still change his code so he isn't one of those doing the assuming. I think someone wanted to restore that scripts be sh complient when they claim to use it, so dash became the default.
Mar 19 2010
Jesse Phillips Wrote:Spacen Jasset wrote:Yes this can be true. In April i start an update from Kubuntu 8.04 LTS to Kubuntu 10.04 LTS. By the way, the line system("mkdir -p " ~ path); comes from project DDebber. It's a cool project, and i have make succesfully deb files for dmd 2.041.then presumably the syntax you are using is a bashism?. You could also say something like: system("bash mkdir -p " ~ path); Messing with your sh symlink may have some undesired consequences.Actually, not messing with it will have undesired consequences. Lots of scripts assume sh points to bash. Though he should still change his code so he isn't one of those doing the assuming. I think someone wanted to restore that scripts be sh complient when they claim to use it, so dash became the default.
Mar 20 2010
noboy <noboy Wrote:By the way, the line system("mkdir -p " ~ path); comes from project DDebber. It's a cool project, and i have make succesfully deb files for dmd 2.041.Totally missed this. Yeah the problem got me thinking about how I use system in that project, and others... still haven't gotten to fixing it.
Mar 24 2010