$ ./bash_scripts/execute_dir.sh "git pull"
Already up to date.
Already up to date.
Already up to date.
[...more omitted...]

execute_dir.sh is just:

for d in */
(cd "$d" && echo "$d" && $1)

@urusan Nice!

Annoying nitpicking tips follow:

I'd use $* instead of $1 so that the quotation of the command is not necessary and I'd make this a function defined in the bashrc for easier portability.

function execute_dir { for d in */; do pushd "$d"; echo "$d"; $*; popd; done }

@UncleAlbie @urusan
Great suggestion, also including pushd/popd!

The $1 could also be replaced with "$@" (including quotation marks), to avoid problems with parameters with spaces. See here for more information:

"What is the difference between $* and $@?"


@floppy @urusan The $* (without quotes) and "$@" (with quotes) both work. So my function is correct.

Nevertheless, good point!

@floppy @urusan Oh. Now I see what you meant.

You're right! The "$@" works better for this.

I completely missed your point. Time for my morning coffee I guess.🙂

Sign in to participate in the conversation

UncleAlbie's Mastodon!

This is a single-user instance and the registration will never be open.

You can choose a public Mastodon instance here.

Feel free to send me a follow request once you've joined the Fediverse!