Give this a look, I just completed it a few days ago about bash scripting.
Bash Scripting for Dummies and Geniuses
The most important points to me are that whatever you write in a bash script is the same stuff you can type in a terminal. Therefore don't try to write it all in one line; instead follow the one-by-one steps you would normally do in a command line; within your script.
The next thing is to actually attempt the script you're asking about, debug it as best as you can, or even get it fully working. If you have trouble, post the script you do have, note what's not working or what your desired intention was that didn't occur. Or even if you're successful and wish to see if others have suggestions you may consider, post the script, say that it does work and that you're wondering if anyone has suggestions as to how to do it differently.
Other links to look at are general guides for bash programming:
- a very good starting guide and I recommend you read the first chapter or two and actually do the first few example scripts. Because if you don't have a fundamental understanding about how to write a bash script at all, you should at least understand why the syntax is the way it is. Anyone can look at their machine and see other scripts. Attempting to copy those and alter them to do what you want is one way to get things done, sometimes a difficult path, but sometimes effective. Problem is, that way is a die toss, and depends on what you started with as an example.
Bash Beginners Guide
- another good starting guide.
Advanced Bash Scripting Guide
- As it says "advanced" however this is close to a De-facto guide on bash programming, it will show you the exact syntax, or what many also call the ABNF, which is a name you can look up, it means the formalized definition of whatever language it is describing; in this case Bash script.