Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Unsuccessfully passing arguments to a bash command

by ikegami (Patriarch)
on Jun 16, 2013 at 05:02 UTC ( [id://1039174]=note: print w/replies, xml ) Need Help??


in reply to Unsuccessfully passing arguments to a bash command

$* reflects the args passed to the function, but you didn't pass any! You merely passed some to bash as you executed the bash command untouchable. You want to execute the bash command untouchable john mike bill, which you can do using
system(q{bash -ic 'untouchable john mike bill'});
or better yet,
system('bash', '-ic', 'untouchable john mike bill');

The latter launches bash directly instead of launching a sh to launch bash.

If the names are variable, you want:

use String::ShellQuote qw( shell_quote ); system('bash', '-ic', shell_quote('untouchable', @names));
or
system('bash', '-ic', 'untouchable "$@"', '-', @names);

If I run untouchable from the command line, it works as expected.

But running the command you passed to system wouldn't have.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-04-24 18:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found