Another bash scripting problem...
ZIYAD A. M. AL-BATLY
zamb at saudi.net.sa
Wed Jun 22 17:03:36 UTC 2005
On Wed, 2005-06-22 at 15:51 +0200, Markus Kolb wrote:
> ZIYAD A. M. AL-BATLY wrote on Tue, Jun 21, 2005 at 15:34:44 +0300:
> > On Mon, 2005-06-20 at 22:04 -0400, Matthew S-H wrote:
> > > <snip>
> > > It is supposed to source all of the files in a directory.
> > > However, it needs to make sure of a few things. It needs to own
> > > ~/.profile_sections, and it shouldn't recurse into sub-directories.
> > > <snip>
> > find ~/.profile_sections -maxdepth 1 -type f
> > or if you want sylinks to be sourced as well:
> > find ~/.profile_sections -maxdepth 1 ! -type d
> > Above will find all the files in a directory.
> Which has the overhead of new shell creation and additional program
> execution. I don't know why he should use any external program if it can
> be done in script as well.
For starter: This is the right way to do it. Using “find” for finding
file-system objects is the Right Thing. Besides, “find” will run only
once in the above script, which wont add much of a stress on the system
while “test -d $file” will run for each object in that directory, and
depending on which version of “test” will run (the “bash” built-in or
the “/bin/test” binary), it might be very huge resource drainer.
After saying all the above, the real reason I suggested the “find” way
is I wanted for him to know how great it is! I used to do the same
things before, until I started to learn about those misc. Linux
utilities. I just wanted to save the reader some time.
Anyway, thanks for sharing.
More information about the ubuntu-users