"Oliver Schneider" <borba...@gmxpro.net> writes: > Hi folks, > > on my Debian box I'm running GNU bash, version 3.2.39(1)-release > (i486-pc-linux-gnu). > > Now, today I ran across a slight problem that I fail to understand. I > have one script that acts as a library of a kind. I.e. it is being > sourced by other scripts and performs some actions upon startup. > > I have the following three files for a minimal working example of the > problem (I trimmed a lot of error/prerequisite handling): * test.sh > (requires chmod a+x test.sh) * common-bash-routines.sh (in the same > folder) * etc/defaults > > test.sh uses common-bash-routines.sh as a library and > common-bash-routines.sh is supposed to inspect the variable SCRIPTCONF > to find out whether it is set. If it is set there are two choices > (inner while loop): 1.) it's a file, it means it will get sourced 2.) > it's a directory > > Both cases can occur in several places (outer while loop). Since the > paths can contain blanks, I resorted to a "while read" loop because > "for" simply would tokenize the file names more than desirable. > > Now since I would like to know whether I have successfully sourced > *something* I was going to set a variable (SOURCED in my > case). However, this variable does not get set in the outer or the > inner loop. Also, using "export" instead of the normal variable > assignment makes no difference whatsoever. How can I carry the > information as to whether I have sourced *something* outside of the > loops? > > > Thanks for any helpful pointers or hints,
You might have to >> the source file name to a temporary file from the sourced scripts and then read that after the loop is done. Since while seems to capture variable setting in its own scope it might be the only way for what you want to do to work. It also seems that for loops don't have the same variable capture that while loops do, so if you could somehow convert them you might now have to use a temporary file. ps. Whatever you used to format your code before sending really messed it up :) -- Burton Samograd -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/hb8w3x57h4....@rex.userful.ca