Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Backticks to capture umask output

by austin43 (Acolyte)
on May 24, 2011 at 20:39 UTC ( [id://906566]=perlquestion: print w/replies, xml ) Need Help??

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

Good day monks, I have a quick question. I am trying to use the output of umask to print output with the following code.
$confirm_SysUmask = `umask`; if ($confirm_SysUmask =~ m/^0037$/) { #if umask output equals 0037 print "SUCCESS: System umask set correctly ($confirm_SysUmask) +\n"; } else { #if umask output not equal to 0037 print "ERROR: System umask incorrect ($confirm_SysUmask)\n"; }
For some reason the string won't capture the output of umask. (The string just shows up blank)Is there something I'm missing? Thanks in advance.

Replies are listed 'Best First'.
Re: Backticks to capture umask output
by saberworks (Curate) on May 24, 2011 at 20:46 UTC
    I recommend you:
    use warnings; use strict;
    This will tell you exactly what the problem is. On my system I get this:

    Can't exec "umask": No such file or directory at umask.pl line 4.
    $ which umask
    Indicates that it's not an actual command you can call. Why aren't you just using the umask perl function?
    umask
    Sets the umask for the process to EXPR and returns the previous value. If EXPR is omitted, merely returns the current umask.
Re: Backticks to capture umask output
by ikegami (Patriarch) on May 24, 2011 at 20:49 UTC

    There is no umask executable.

    $ perl -E'say `umask` // ( $! != -1 ? $! : sprintf("\$?=%04x", $?) );' No such file or directory

    You are trying to execute a bourne shell command without involving a bourne shell. So invoke the shell:

    $ perl -E'say `/bin/sh -c umask` // ( $! != -1 ? $! : sprintf("\$?=%04 +x", $?) );' 0077

    Of course, you should just use the builtin umask.

    $ perl -E'my $umask = umask; say defined($umask) ? sprintf("%04o", $um +ask) : $!;' 0077
      Nevermind I get what you're saying. I tried invoking /bin/sh and it worked! Thanks alot.
      When I type 'umask' into the terminal (using bash) it outputs 0037 though...
        So use «/bin/bash -c umask» instead of «/bin/sh -c umask»
        Yes, but what's your point?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-23 06:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found