You are not logged in.
When I finally got my new laptop I sat down and typed "git clone git@.../{foo,bar,baz,bit,bat,boo}", pulling in all my projects. Would they all build on this machine?
$ cd foo; make
$ cd ../bar; make
$ ...
This gets old quickly so I did a quick script:
$ for x in *; do cd $x; make; cd ..; done
Better, but I couldn't tell what projects all these messages belonged to. Enter within:
$ within * -- make
foo: make: Nothing to be done for `all'.
bar: make: Nothing to be done for `all'.
baz: make: Nothing to be done for `all'.
...
It was a good exercise in writing an event driven C program as all child processes (possibly concurrently, there's a -j flag) needed to have their stdout and stderr processed to add the prefix. Initially I got a bit stuck with select() and went with BSD's kqueue but eventually I got it working with select() - and on Linux.
(There is some overlap with xargs but the prefixing is very useful to me.)
Last edited by sjmulder (2018-11-13 12:50:06)
Offline
Why not simply
$ for x in *; do make -C "$x"; done
Inofficial first vice president of the Rust Evangelism Strike Force
Offline
Why not simply
$ for x in *; do make -C "$x"; done
That works well for commands that traverse directories themselves (like make) but not things like git status. It's also hard to tell apart the output from the different invocations. 'within' will prefix all output with the directory.
Offline
Absent the desire to have fun implementing simple concepts in a new programming language like C, I'd just use:
$ for x in *; do echo "$x: "; cd "$x"; make; cd ..; done
echo isn't a hard concept to implement in bash over C.
...
Remains to be seen whether linebreaks between the directory name and multiline stdout is preferred...
Last edited by eschwartz (2018-11-13 13:56:38)
Managing AUR repos The Right Way -- aurpublish (now a standalone tool)
Offline
I think the salient point of OP's program is, that it allows to run a command in multiple directories in parallel (or just concurrently, idk) so that if there is more than one line of output of per-directory run program, it prepends the directory name to the respective output line so that one can see, from which "thread" the output is actually coming.
Inofficial first vice president of the Rust Evangelism Strike Force
Offline
echo isn't a hard concept to implement in bash over C.
But that's not what it does – it prepends output to every line.
Anyway, just putting it out there for people who might find it useful. I'm well familiar with the Unix swiff army knife but none of the blades scratched this particular itch.
Offline