What would I do without the Linux shell? The sheer number of mouse clicks required to do this in Windows would result in instant and painful arthritis.
For each Makefile in any child directory below pwd, It’s looking for a broken include string where the include was specified after the library and if it finds this case, it rewrites that part so it’s include/library. It’s basically the same thing done over and over for each include that might exist in any Makefile.
This has to be the longest and dumbest string of commands ever used in a terminal.
for x in `find . -name Makefile`; do grep -e “-I\$.HOME./libalpha/include” $x; if [ $? == 0 ]; then sed -i ’s/\/libalpha\/include/\/include\/libalpha/’ $x; fi; done; for x in `find . -name Makefile`; do grep -e “-I\$.HOME./libbravo/include” $x; if [ $? == 0 ]; then sed -i ’s/\/libbravo\/include/\/include\/libbravo/’ $x; fi; done; for x in `find . -name Makefile`; do grep -e “-I\$.HOME./libcharlie/include” $x; if [ $? == 0 ]; then sed -i ’s/\/libcharlie\/include/\/include\/libcharlie/’ $x; fi; done; for x in `find . -name Makefile`; do grep -e “-I\$.HOME./libdelta/include” $x; if [ $? == 0 ]; then sed -i ’s/\/libdelta\/include/\/include\/libdelta/’ $x; fi; done; for x in `find . -name Makefile`; do grep -e “-I\$.HOME./libecho/include” $x; if [ $? == 0 ]; then sed -i ’s/\/libecho\/include/\/include\/libecho/’ $x; fi; done; for x in `find . -name Makefile`; do grep -e “-I\$.HOME./libfoxtrot/include” $x; if [ $? == 0 ]; then sed -i ’s/\/libfoxtrot\/include/\/include\/libfoxtrot/’ $x; fi; done; for x in `find . -name Makefile`; do grep -e “-I\$.HOME./libgolf/include” $x; if [ $? == 0 ]; then sed -i ’s/\/libgolf\/include/\/include\/libgolf/’ $x; fi; done; for x in `find . -name Makefile`; do grep -e “-I\$.HOME./libhotel/include” $x; if [ $? == 0 ]; then sed -i ’s/\/libhotel\/include/\/include\/libhotel/’ $x; fi; done; for x in `find . -name Makefile`; do grep -e “-I\$.HOME./libindia/include” $x; if [ $? == 0 ]; then sed -i ’s/\/libindia\/include/\/include\/libindia/’ $x; fi; done; for x in `find . -name Makefile`; do grep -e “-I\$.HOME./libjuliet/include” $x; if [ $? == 0 ]; then sed -i ’s/\/libjuliet\/include/\/include\/libjuliet/’ $x; fi; done;

Just in case you’re wondering, here’s the whole police letter alphabet:
ALPHA, BRAVO, CHARLIE, DELTA, ECHO, FOXTROT, GOLF, HOTEL, INDIA, JULIET, KILO, LIMA, MIKE, NOVEMBER, OSCAR, PAPA, QUEBEC, ROMEO, SIERRA, TANGO, UNIFORM, VICTOR, WHISKY, ZULU
I’m showing the example to show that you don’t need to come up with fancy or efficient means of performing a task. There are much better ways of doing this using awk or sed.
But sometimes you just want to get something done and what you already have works. It’s not always worth your time to refactor and refine. Life is short, just copy and paste over and over to repeat and move on!
Ahh, much better but that wasn’t really the point. I picked an obscure example because it’s just something that came up on the fly. If for some reason someone reads this because they’re trying to do the same thing or something similar, your method is much better and I hope they’d recognize that my “Longest dumbest bash command ever” wasn’t a serious attempt at solving the problem in the first place.
I am just curious then, what is the point of this article?
What confuses me is that In your article you say “It’s not always worth your time to refactor and refine. Life is short, just copy and paste over and over to repeat and move on!”
Implying that the point is to get it done quick and move on.
As you said, my example was not only more simple but faster to write than the very first for loop you wrote and I don’t have to go back and copy it, paste it 9 more times and edit it! Which means you could have just written and moved on WAY faster.
Yet in your return comment you say this article “wasn’t a serious attempt at solving the problem in the first place”
So if it is not about showing a fast/easy way to complete a task, and it is not about having to write a LONG command as the only way to “solve” a problem (as the title suggests)… then you should be able to see where my question stems from.
Why so serious?
1:40 pm
for x in `find . -name Makefile`; do sed -i -r ’s/\/lib(.*)\/include/\/include\/lib\1/’ $x; done
These commands do the same thing, I have tested this on Fedora 14 and CentOS.