Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: Unsuccessfully passing arguments to a bash command

by ikegami (Pope)
on Jun 16, 2013 at 05:02 UTC ( #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));
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1039174]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2017-10-17 02:29 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (218 votes). Check out past polls.