Why doesn't this work?
find . -maxdepth 1 -type f -print0 | xargs -0 .
All I get is xargs: .: Permission denied
.
Why doesn't this work?
find . -maxdepth 1 -type f -print0 | xargs -0 .
All I get is xargs: .: Permission denied
.
When you run . file
, you invoke a the shell builtin .
. Your xargs
variant tries to execute the current directory.
Even if that did invoke the builtin, that command runs in a subshell, so all the "sourcing" would be useless.
Use shell globbing and a loop for that:
for file in * ; do
if [ -f "$file" ] ; then
. "$file"
fi
done
@Mat's solution is the cleanest, but in case you're interested in some bash-fu for the fun of it, the following solution, based on the original find
command, works, too:
eval $(find . -maxdepth 1 -type f -exec echo . \'{}\'';' \;)
find
is used with -exec
to construct a sourcing command for each file found, e.g. . './foo';
. Note the escaped single quotes to ensure that filenames with special chars. are handled properly.find
will return a newline-separated list of sourcing commands; by using command substitution ($()
) without double-quoting, the shell folds these lines into a single line using a space each as the separator.eval
executes the full list of sourcing commands in the context of the current shell (verified on OS X 10.8.1).NOTE: One potential problem with this solution is that the command string can get large - possibly too large - with many files and/or long filenames present.