views:

85

answers:

2

I need to allow several applications to append to a system variable ($PYTHONPATH in this case). I'm thinking of designating a directory where each app can add a module (e.g. .bash_profile_modulename). Tried something like this in ~/.bash_profile:

find /home/mike/ -name ".bash_profile_*" | while read FILE; do
source "$FILE"
done;

but it doesn't appear to work.

Thanks in advance if you can offer a fix or any working solution.

-Mike

+5  A: 

Wouldn't

 for f in ~/.bash_profile_*; do source $f; done

be sufficient?

Edit: Extra layer of ls ~/.bash_* simplified to direct bash globbing.

Dirk Eddelbuettel
for f in ~/.bash_profile_*; do source $f; doneshould work too; bash can handle the globbing.
Emil
Emil: You're correct. Thanks for the suggestion.
Dirk Eddelbuettel
Dirk, you should edit your answer with Emil's suggestion.
glenn jackman
+4  A: 

I agree with Dennis above; your solution should work (although the semicolon after "done" shouldn't be necessary). However, you can also use a for loop

for f in /path/to/dir*; do
   . $f
done

The command substitution of ls is not necessary, as in Dirk's answer. This is the mechanism used, for example, in /etc/bash_completion to source other bash completion scripts in /etc/bash_completion.d

Jefromi
Perfect, thanks. I would have accepted this as the answer but it came in just after I finished accepting the first one. Note: Ended up with the same result in comments of other answer. Peace, Mike
Mike Bannister