Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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));
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.


Comment on Re: Unsuccessfully passing arguments to a bash command
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (13)
As of 2014-12-22 14:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (119 votes), past polls