Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hello, long time lurker, first time poster. I'm trying to use system() in list mode like so:
my @a=("echo", "\$PATH"); system(@a);
However, I just get $PATH as output instead of the value of my path.
Background:
1. Linux.
2. I'm not actually echo'ing anything in my real code, but I can't even get this unit test to work. My code is supposed to set $PATH, then run a command on the same line, in the same shell.
3. Unless I can temporarily set my $ENV{PATH} variable without having to manually reset it, then don't tell me to use that. It makes no sense to me to set a global variable for a temporary shell. Apparently other-forum goers don't know about OOP.
4. I successfully did this using system() in scalar context (one string arguement, ok it's not actually scalar but w/e).
5. I'm trying to do this in order to handle spaces in path names (which shouldn't appear in linux but it's better safe than sorry). If another way can be used to resolve this issue then that works too!

Thanks

Edit:
Apparently monks can't read either. So far most of the answers provided are relevant to what I'm trying to achieve.
5. I'm trying to do this in order to handle spaces in path names (which shouldn't appear in linux but it's better safe than sorry). If another way can be used to resolve this issue then that works too!

Edit 2:
Ok here's my code. The second system call is supposed to set my PATH to something (it's actually something but not relevant; also, long), then run a script.
#!/usr/bin/perl -w use strict; use warnings; my $path = "/home/john/test/test a folder"; my @arr = ("echo", "\$PATH"); system (@arr); my @script = ("env", "PATH=\"foo\"", "bash", "$path/test.sh"); system (@script);
For output I get:
$PATH
env: bash: No such file or directory


Any help is appreciated. Bullsh*t not so much.

In reply to System() in list mode? by 1337John

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-19 12:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found