Skip to main content

Timeline for Why I should avoid loops in shells?

Current License: CC BY-SA 3.0

4 events
when toggle format what by license comment
Apr 26, 2015 at 10:44 comment added mikeserv @StéphaneChazelas - find's probably overkill - recursing a tree and executing unknown scripts - likely as root - is crazy. If find called a script which altered the mount tree it could go really bad. And renaming files in /etc should be avoided. As I see it the op should handle only files named to some expected conformity - like the common 1-99 prefixes - and just dot each in the order theyre globbed in a for loop - each in its own subshell if need be. I believe that's something like what he intends to do now anyway.
Apr 26, 2015 at 8:43 comment added Stéphane Chazelas @Costas, that would run one bash per file and embed {} in the code is a lot worse practise than using loops. I'd still use a loop like -exec sh -c 'for script do...' sh {} + here or (GNUly): find ... -printf 'Executing %f\n' -exec {} \; -exec mv {} {}.done \; (which would run the mv only if the script succeeds).
Apr 25, 2015 at 22:38 comment added Costas @StevenPenny find /etc/postinstall -name '*.sh' -exec bash -c 'echo Runing {} ...; "{}" ; mv "{}" "{}.done"' \;
Apr 25, 2015 at 22:22 history answered Janis CC BY-SA 3.0