Andrew Benton wrote:

<snip>I've just started reading the Advanced Bash Scripting Guide http://personal.riverusers.com/~thegrendel/abs-guide-3.3.tar.bz2 and on what I've read so far, I recommend it.


Andrew, thanks for the recommendation on the book. It's really informative and laid out well. Plenty of discussion and examples to play with.

After reading some of the sections I still have some "bash" questions. I have typed the /etc/profile directly from pp. 55-56 of BLFS 6.0 and am happy with the results. However, I want to learn how this script works. I have an "intellectual understanding" of the commands and concepts, but I can't make them work using a pencil and paper. I'm trying to make $PATH=/bin:/usr/bin:/sbin/:/usr/sbin for root--just as it is on my PC--while $PATH=/bin:/usr/bin for everybody else. My problem may be that I really don't understand what happens to arguments when they are passed to a function--what gets stored in the position parameters--or the indirect variable references. Anyway let me try to explain what I think happens as the functions are called.

Globally, $PATH=/bin:/usr/bin and now I log on as root. /etc/profile calls 'pathappend' with the single argument /sbin:/usr/sbin. ($IFS which is global is still set to whitespace. Therefore this is a single argument. This could be my first "conceptual error.")

So now <pathappend> sets $1=/sbin:/usr/sbin and $2 is at least not set if not null. <pathappend> first calls <pathremove> and passes $1 and $2 as arguments. So now $1 is still /sbin:/usr/sbin and $2 is set but null.

(This is the second spot at which my logic may fall apart. Since ' : ' is "tightly quoted"--there must be "whitespace" in the delimiters, I'm not "breaking apart" the values of the positional variables.) $1 is still /sbin:/usr/sbin and since $2 is set but null, $PATHVARIABLE=$PATH=/bin:/user/bin. Now comes the real obstacle.

I'm trying to expand ${!PATHVARIABLE} for the statement 'for DIR in ${!PATHVARIABLE}. This is a summary of the information from "Advanced Bash Scripting Guide," p. 420, "Example 35-2. Indirect variable references-the new way." If I have one variable whose value is the name of another variable, I can make the value of the first variable the value of the second variable. In other words

a=something
something=z
echo "a=${!a} gives z.

According to my logic $PATHVARIABLE=/bin:/usr/bin and there is no variable named /bin:/usr/bin.

I also cannot mentally expand the expression
$PATHVARIABLE="${!PATHVARIABLE:+:${!PATHVARIABLE}}"

I know this is pretty muddy. I've re-read what I've written three times and I haven't seen any other way of expressing it.

I hope someone can either point out the error(s) in my logic or point me in a direction with which I can think this through.

Thanks,

Dan

--
http://linuxfromscratch.org/mailman/listinfo/blfs-support
FAQ: http://www.linuxfromscratch.org/blfs/faq.html
Unsubscribe: See the above information page

Reply via email to