With so many people just getting started in Linux, I thought it'd be a good idea to give them a place to learn Bash programming.
The basic curriculum is
- Variables
- Assignments and Basic Operators
- The shell environment
- if/then and && and ||
- Functions
- Parameters/arguments
- Return status
- Arrays
- Loops
- String Operations
- Number Operations
- Bash Special Variables
- File Testing
- Command/Process Substitution
- Pipelines, more on STDIN/STDOUT/STDERR
- Regular Expressions
- Commonly Used Externals (sed,awk,grep,sort,bc,etc)
- Testing with Bats
The trouble with teaching these things is that everything gets intertwined. What do you teach first? The chicken or the egg? My feeling is that it doesn't matter. You're going to have to revisit the thing at some point. It's an ongoing process to keep learning programming concepts. There's no way to present the entire gammut in one entirely-perfect-for-everyone way. You start some place and keep going, learning what you need as you need it. That's how I've approached this course.
I think the most useful approach is to use real world problems. Do some sort of project that actually solves a problem or does a task that you can use. In the beginning, this will be hard, so we'll have to stick to simple problems for a long time. Eventually, we'll get to progress to more interesting projects. But that's how it is with any programming language. You start with very simple projects and progress as far as you want to go.
Here are some examples:
- create a function that adds two numbers together
- create a function that multiplies two numbers together
- create a function that echos 'even' or 'odd' based on a given number
- create a function that finds a shell script named waldo and replaces a note at the top saying "I've been found"
- create a fizzbuzz script
- solve some classic beginner programming problems
- introduce exercism.io and the bash track