When handling parameters from the command line I usually want one or two parameters to have a default value. In Bash I can achieve this through:
Where “DIRECTORY_FROM_COMMAND_LINE” is just another variable and thus can be 1 (for $1).
Part of what I find really hard with Bash scripts is encapsulation and error handling. It all became a tiny bit better when I discovered how I can print the call stack when something occurs. Check out this blog post for how to print the call stack.
I’m thinking this fits nicely with trap, but I’ll have to try that another day. 🙂
I’m currently working on automating our deployment with Bash scripts. For a TDD loving Java programmer it can be quite hard to figure this all out, but I’m getting better. I don’t ever think I’ll start to love it, but maybe one day I can like it. 😉 I’ll try to share small snippets of what I learn here.
I always have these early in my scripts. That way I know if anything fails (set -e) and if any variables is undefined (set -u).
Any other tips?
Daniel Spiewak has a nice post on comparing JRuby with Scala for a simple script. Some minor errors, and discussion about how to write them best in the comments. But overall a pretty good comparison.
At least for a Java guy like me, I think Scala will be much easier to pick up. And I even get to keep my strong typing. 😉