CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Using variable from shell script in perl file

 



viored
New User

May 29, 2013, 12:10 PM

Post #1 of 5 (273 views)
Using variable from shell script in perl file Can't Post

Hey,

So I have a shell script that outputs some variables, call them $a and $b. I know in shell scripting if I wanted to use the variables in another shell script I'd do


Code
sh code.sh "$a" "$b"


How can I do something similar with perl?


FishMonger
Veteran / Moderator

May 29, 2013, 12:50 PM

Post #2 of 5 (269 views)
Re: [viored] Using variable from shell script in perl file [In reply to] Can't Post

I'm not a shell programmer, so I'm not sure if the quotes are required, but you can pass the vars to the perl script in the same way.


Code
perl code.pl "$a" "$b"

The vars would be in Perl's @ARGV array.


Laurent_R
Enthusiast / Moderator

May 29, 2013, 2:21 PM

Post #3 of 5 (265 views)
Re: [FishMonger] Using variable from shell script in perl file [In reply to] Can't Post

I would say that quotes are required neither in the shell script call, nor in the perl script call.


(This post was edited by Laurent_R on May 29, 2013, 2:21 PM)


FishMonger
Veteran / Moderator

May 29, 2013, 2:31 PM

Post #4 of 5 (262 views)
Re: [Laurent_R] Using variable from shell script in perl file [In reply to] Can't Post

My reading of the question indicates that the calls are being made within a shell script, which is why I questioned the use of the quotes. If these calls are made from the command line, then the quotes shouldn't be needed. It comes down to shell syntax, which I can't answer.


(This post was edited by FishMonger on May 29, 2013, 2:32 PM)


Laurent_R
Enthusiast / Moderator

May 29, 2013, 2:49 PM

Post #5 of 5 (259 views)
Re: [FishMonger] Using variable from shell script in perl file [In reply to] Can't Post

Yes, but even though I do not claim to be a shell expert (I am doing more and more things in Perl, and less and less in shell), I have written dozens of thousands of lines of code in shell, and I can say that you usually don't need to do that in a shell program (at least not in the shells that I know), unless you want to do something quite special, such as hiding special characters so that the shell does not sees it. For example, assuming you want to pass to a program (Perl or other) the following arguments "foo | bar", you would probably (I haven't tried such bizarre syntax) need the quotes to prevent the shell from interpreting '|' as a pipe between shell commands. But that's exactly what you would also do on the shell command line in such a case.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives