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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.