Investigating /etc/profile

Dan McGhee farmerdan at i-rule.net
Fri Apr 8 15:39:23 PDT 2005


Simon Geard wrote:

>On Thu, 2005-04-07 at 19:56 -0500, Dan McGhee wrote:
>
>  
>
>>I also cannot mentally expand the expression
>>$PATHVARIABLE="${!PATHVARIABLE:+:${!PATHVARIABLE}}"
>>    
>>
>
>Can't blame you - that's pretty ugly. I've seen (and written) worse
>though, so let's break it down:
>
>The exclamation marks are like a pointer - when you see the notation
>!PATHVARIABLE, replace it with the value of $PATHVARIABLE. So if
>$PATHVARIABLE was equal to the string "PATH", it would be as if the
>following command was used instead (note the exclamation marks are
>gone):
>
>    $PATHVARIABLE="${PATH:+:${PATH}}"
>
>Of course, the left side of the assignment has a dollar sign next to it,
>so that also gets expanded. So now, you have:
>
>    PATH="${PATH:+:${PATH}}"
>
>That then becomes a simple case of the alternate value syntax, although
>the presence of the second colon makes it look a bit more complicated.
>Basically, if the variable named before the first colon is set, then it
>replaces it with the value after the first colon, which would be the
>string ":$PATH".
>
>In short, it takes the variable named in $PATHVARIABLE, and if it's set
>to something, prepends a colon.
>
>
>Simon.
>  
>
Simon, thank you very much.  With your explanation I was able to 
understand what the script does.  Your explanation was much clearer than 
any I had encountered before I read your message.

As I journey through BLFS, I'm going to keep my eyes peeled for a script 
that uses PATHVARIABLE, since that variable gets exported at the end of 
'pathremove' but reset in the other functions of /etc/profile.

Thanks again.

Dan



More information about the blfs-support mailing list