Hacker News new | past | comments | ask | show | jobs | submit login
How to do metaprogramming (aka macros) in bash (simpletondigest.wordpress.com)
6 points by jemeshsu on Jan 6, 2012 | hide | past | favorite | 5 comments



I was with him until he mentioned that this is included in a real library and is intended for use... Why would you ever use this in your scripts? Why not any other sane language with normal quoting rules?


I would never suggest to anyone that they use bash when there is a better alternative, but it often happens that you start with a "toy" script and then it ends up growing and growing. Even in my job (I'm a consultant) I run into massive bash scripts that do complex jobs.

Not everyone is going to rewrite, and if they're not they should have tools available to them to help make their scripts more robust. The @macro alias is just a helpful tool for achieving that without quadrupling the size of your script.

Thanks for the feedback.


I tried this before, but the quoting is a nightmare.


There were a number of nightmarish aspects of it, but with the latest iteration I haven't had any problems. I can print very complex code from my macro functions and they will be evaluated without problems. You do have to use printf '%q ' sometimes though.


Yes, I would think that actually continuing to work on it you would find some better ways to work around it. Shell is still one of my favorite languages for textual data munging.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: