Sourcing a Directory
ZIYAD A. M. AL-BATLY
zamb at saudi.net.sa
Mon Jun 13 03:55:55 UTC 2005
On Mon, 2005-06-13 at 06:32 +0300, ZIYAD A. M. AL-BATLY wrote:
> On Sun, 2005-06-12 at 21:45 -0500, Carl Karsten wrote:
> > Matthew S-H wrote:
> > > How do I "source" a directory?
> > >
> > > ie: How might I have a line in my "~/.bash_profile" that automatically
> > > runs "source ~/.bash_profile_pieces/*" where the "*" evaluates to each
> > > file in ~/.bash_profile_pieces/"? I tried running it with the star and
> > > it only 'sourced' the first file (alphabetically).
> > >
> >
> > Um, here is an off the cuff guess:
> >
> > $ find ~/.bash_profile_pieces/* -exec echo source {} \;
> >
> > the "echo" will show you the commands it would execute - if it is what you want,
> > take out the echo.
> >
> > Carl K
> >
> No, that wont work.
> Here's a solution:
> export $(cat ~/.bash_profile_pieces/*)
>
> Ziyad.
>
Okay, I'm wrong (again, what's new about that!), that only works with
variables that aren't “export”ed and nothing else!
Here's a very ugly solution:
d="$HOME/.bash_profile_pieces" && find "$d" -type f -print0 | xargs -0 -i cat {} >"$d/all" && source "$d/all" && rm -f "$d/all"
(note: you can't use “~” with the quotation marks! Either use “$HOME”
as above, or remove the quotations but don't use a directory with a
space(s) in it's name!)
Sorry, that's the only solution that I know.
Ziyad.
More information about the ubuntu-users
mailing list