Perl Monk, Perl Meditation | |
PerlMonks |
Re^3: values from perl to sh scriptby polettix (Vicar) |
on Jul 14, 2005 at 18:31 UTC ( [id://475002]=note: print w/replies, xml ) | Need Help?? |
(Some of the following notes surely apply to bash, don't know about other shells).
You can use the backtick operator or its equivalent (and prefearable, IMHO): The latter has the added advantage of allowing nested subshell invocations. If your return value can have newlines, I'd suggest to use double quotes: And yes, you can use read as well, but you have to be extremely careful about what you want to do. Suppose you have the following script: and you want to set the variable value to the contents of the last line: you obtain: Note that after the first while the variable value has not been modified. This is due to the fact that the first while cycle is being executed inside a subshell. OTOH, the second while is executed directly by the "current" shell. This may lead to problems if you pass a lot of data back, anyway. Note that there are also other ways, but there is too little space on the side of this post to write them. Flavio
In Section
Seekers of Perl Wisdom
|
|