Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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 wandering the Monastery: (7)
As of 2018-02-25 04:17 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (312 votes). Check out past polls.