Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

"not enough arguments" with 'mkdir' command

by nysus (Parson)
on Dec 09, 2003 at 00:29 UTC ( [id://313318]=perlquestion: print w/replies, xml ) Need Help??

nysus has asked for the wisdom of the Perl Monks concerning the following question:

On a Cobalt RaQ4 server, running Perl 5.005_03, this line:
mkdir 'directory';
yields this error
Not enough arguments for mkdir
When I try to supply a mask argument to the above, the directory gets created but not with the mask I used. I'm guessing this all has something to do with the funky way a Cobalt server runs Perl code. Can someone tell me what's going on and a good workaround?

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff";
$nysus = $PM . $MCF;
Click here if you love Perl Monks

Replies are listed 'Best First'.
Re: "not enough arguments" with 'mkdir' command
by Roger (Parson) on Dec 09, 2003 at 00:57 UTC
    You could type perldoc -f mkdir from the command prompt to get the documentation for the 'mkdir' function. And I would also check for the return status of mkdir to see if it has succeeded or not.

    Another point is that file masks are octal numbers, so that
    mkdir 'dir', 700; # incorrect
    is not the samething as
    mkdir 'dir', 0700; # correct
    Having said that, you can certainly overcome this problem by a subsequent call to 'chmod' -
    chmod 'dir', 0700;
      OK, after looking at the perldoc, it says nothing about the mask being optional. You are correct. Thanks for this. I was also supplying the mask as a string literal, not an integer.

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff";
      $nysus = $PM . $MCF;
      Click here if you love Perl Monks

•Re: "not enough arguments" with 'mkdir' command
by merlyn (Sage) on Dec 09, 2003 at 11:15 UTC
    I see a lot of responses talking about this argument as the "mask" argument. That's the "mode" argument, or "permission mode" to be a little more verbose.

    Perhaps the confusion is that the bits of the "umask" are cleared out of this value, per normal Unix policy on creating new files and directories. If it was a "mask", what is it masking? {grin}

    And yes, this was mandatory in Perl 2 through Perl 5.5, and became optional in Perl 5.6.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      That's the "mode" argument, or "permission mode" to be a little more verbose.

      I agree that the argument should be named "mode", but that's not how it is documented. In 5.8's perlfunc:

      mkdir FILENAME,MASK mkdir FILENAME

      Note: in 5.005, it was called mode.

Re: "not enough arguments" with 'mkdir' command
by jsprat (Curate) on Dec 09, 2003 at 01:01 UTC
    When I try to supply a mask argument to the above, the directory gets created but not with the mask I used.

    When you say "but not with the mask I used", what exactly do you mean? Do you supply '0777', but it is created '0755'?

    What is the mask you are supplying, what are the permissions on the directory, what are you expecting the new directory's permissions to be - and finally, what is your umask?

      OK, I was supplying the mask as a string literal, surrounded by single quotes, which gave me interesting results. When I supply an integer in octal, the correct permissions are set. Thanks for the help.

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff";
      $nysus = $PM . $MCF;
      Click here if you love Perl Monks

Re: "not enough arguments" with 'mkdir' command
by duff (Parson) on Dec 09, 2003 at 00:38 UTC

    Not enough clues have been given, but I can guess that it didn't use the mask you thought you specified because you used the wrong format. e.g., 777 instead of 0777. As to why mkdir complains about the number of arguments ... are you sure that's a perl error?

      mask was required in 5.005_03. It became an optional argument for mkdir in 5.6, iirc.

      are you sure that's a perl error?

      The mask argument is optional and defaults to 0777. He should be able to get by with a single argument. I agree with you that he didn't provide enough clues.

      Update: Oops, jsprat++ is completely correct. The mask is not optional in 5.005. Sorry for any confusion.

      -sauoq
      "My two cents aren't worth a dime.";
      
      I tried both 777 and 0777. But I get the error when I don't supply the mask. Here's the entire error message:
      Not enough arguments for mkdir at ./test_file.pl line 3, near "'ding'; +" Execution of ./test_file.pl aborted due to compilation errors.
      The entire program is just one line.

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff";
      $nysus = $PM . $MCF;
      Click here if you love Perl Monks

        The entire program is just one line.

        Can you show us that one line then?

        Does

        perl -e "mkdir q(foobar), 0777"
        work for you?

        Update: Changed to include umask as jsprat's comment is correct.

        -sauoq
        "My two cents aren't worth a dime.";
        

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://313318]
Approved by mpeppler
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-24 22:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found