Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I've learnt the basics of programming in bash. I'd like to study a few examples of bash scripts so that I can learn good habits for bash scripting.

In particular, I'm interested in examples of bash scripts that show:

  • how to process arguments and trigger conditional functionality
  • how to check for input errors
  • how to perform command completion
  • how to organise a bash script into functions, commands, and so forth
  • how to present help messages

For example, I learnt a lot from autorandr on github. Are there any other such scripts or script repositories where I could learn about bash scripting conventions?

share|improve this question
1  
One note about where not to look: many system init scripts packaged by most distros in /etc or wherever are full of bad shell scripting practices so you should avoid using those as examples. –  jw013 Oct 13 '11 at 1:33
    
Don't know why this got a downvote, +1 –  MaxMackie Oct 13 '11 at 2:58
1  
Are there "good" coding conventions for bash? The way I see it, when you use bash you're generally more interested in making it do its (extremely limited) job as efficiently and as portably as possible. If you want elegant and clean code, you use an actual programming language. –  Shadur Oct 13 '11 at 7:11

1 Answer 1

Shameless plug, but you did ask for examples:

And if you want a good reference, use Greg's Wiki. It's a no-nonsense readable garden of chaos and beauty, with a pragmatic approach to getting things done in the best way. Just be really, really careful to investigate properly before asking anything on #bash - They can be fierce.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.