Bash, Env, Set, Export, Pipes....Scripting
Greetings,
Why doesn't this work: CASE #1 [slammer]# perl getlinks.pl -d http://knihovny.cvut.cz/ftp/pub/vmware/ . '\.gz$' | grep any-any | (read any; export any) [slammer]# echo $any [slammer]# nor this: CASE #2 [slammer]# perl getlinks.pl -d http://knihovny.cvut.cz/ftp/pub/vmware/ . '\.gz$' | grep any-any | read ANY; export ANY=$ANY [slammer]# echo $ANY [slammer]# nor this: CASE #3 [slammer]# ls | grep vmware-any-any | (read old; export old) [slammer]# echo $old [slammer]# nor this: CASE #4 [slammer]# ls | grep vmware-any-any | (read old; export old=$old) [slammer]# echo $old [slammer]# given the following: CASE #1 and CASE #2 [slammer]# perl getlinks.pl -d http://knihovny.cvut.cz/ftp/pub/vmware/ . '\.gz$' | grep any-any | (read any; echo $any) http://knihovny.cvut.cz/ftp/pub/vmwa...date113.tar.gz and this: CASE #3 and CASE #4 [slammer]# ls | grep vmware-any-any | (read old; echo $old) vmware-any-any-update113.tar.gz Thanks.... |
When you pipe things from one point to another, each guy is running in his own process. This means that variables defined in one of these processes won't have their definitions brought back to the parent proceess.
This is the way to do what you want: Code:
ANY=$(fred | grep barney) |
Moved: This thread is more suitable in the Programming Forum and has been moved accordingly to help your thread/question get the exposure it deserves.
|
wjevans_7d1@yahoo.co - i know the basics of env var's, and what you have suggested will not solve the problem I am having. Also, as you can see from my examples, piping inside of parens keeps them all inside of the first child which is evident in the fact that at the end of the run, i can echo the correct value...as well, from everything I have read, exporting is supposed to make variable changes much more permenant, remaining for the life it's parent shell.
So, once more, please someone, tell me what in the hell it is that I am missing....it's really starting to piss me off. |
From Advanced Bash-Scripting Guide, Chapter 4
Quote:
Code:
perl getlinks.pl -d http://knihovny.cvut.cz/ftp/pub/vmware/ . '\.gz$' | grep any-any > /tmp/somefile |
yeah, I had that working.
Well I went back and thought about what wjevans said and it hit me.... [slammer]# any=`perl getlinks.pl -d http://knihovny.cvut.cz/ftp/pub/vmware/ . '\.gz$' | grep any-any` [slammer]# echo $any http://knihovny.cvut.cz/ftp/pub/vmwa...date113.tar.gz Oh the power of the back tick, behold.... |
Might I make a suggestion?
Instead of saying `blah`, say $(blah). There are no advantages to back ticks. The $() syntax has the advantage that it can be nested. |
All times are GMT -5. The time now is 01:37 PM. |