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

execute_dir.sh is just:

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

@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 $@?"
unix.stackexchange.com/a/41595

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

Nevertheless, good point!

Follow

@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
Mastodon

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!