LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Educational Bash projects (https://www.linuxquestions.org/questions/programming-9/educational-bash-projects-832022/)

theKbStockpiler 09-14-2010 01:24 AM

Educational Bash projects
 
Have you ever seen a hobbyist electonic Kit? They have projects that try to teach what each type of component does. Is there such a thing for Bash? It would tend to be aimed at tasks that are suitable for bash and not attempt to go over the line of what is better suited as a compiled program. Intuitively I think maybe something that timestamps files; when you download them, or anything else that would keep a home PC better organized is practical. Any ideas or feedback would be appreciated!

rcbrgs 09-14-2010 03:34 AM

I guess pretty much anything can be automated by clever shell scripts. So to come up with tasks you can have as a rule of thumb "how do I do X automatically?"

catkin 09-14-2010 09:22 AM

How about scripts to backup files, to test Internet connectivity (and identify failing link or report external IP if Internet is up), to test response of a list of DNS servers, to delete temporary and cache files (could be dangerous!), to report any file systems more than some percentage full? For better teaching these scripts could a) trap all errors b) accept command options with/without option arguments (use getopt or getopts) c) read configuration data from a configuration file d) include an option (usually -h or --help) to print extended help e) ensure there is no other instance of the same script running.

smeaton 09-23-2010 05:26 PM

This may be off point, but there is a small linux sys., called inx (inx-1.1.iso)that is
designed to teach the command line,it's text only and very well designed for learnig
the cli. -- smeaton

GrapefruiTgirl 09-23-2010 05:56 PM

Some good suggestions above. Catkin has the right idea - bash is perfectly suited to doing simple or even very complex system admin tasks such as one might want to do on a somewhat regular basis on their own machines. Many regularly scheduled tasks that are done by cron daemons are shell scripted. Just look around your machine and think about what you do regularly that makes you "wish you has a simple way to do this every time I do it!".

When I first got interested in learning bash, I began with a rather large shell script written by someone else; it was for configuring an iptables firewall - and I understood very little of what I was reading when I opened up the script in my editor. I started just perusing through it, editing comments for grammar; comparing comments to the code that they referred to, and trying to understand how that piece of code did what the comments said it did. This procedure got me a little familiar with syntax, and once I began to understand syntax, I began copying chunks of the code into my console and running them standalone, to see what they did. I'd adjust or change something, and try it again. Trial and error basically, but I find (for me anyhow) it's more productive learning this way than to copy examples from tutorials and run them. Tutorials are great for basic basics, for concepts, but for real usable situations, they aren't always the way to go.

Coming back to the "what do I need on my machine" thing.. Another example for me was needing a way to stop, re-configure, and restart the network on my firewall machine every time our dialup connection either came up or went down. There wasn't a script I could find that did precisely what I needed, and (using kppp at that time) KPPP did not have enough flexibility to do what I needed on its own; so I put some small scripts together (into one script ultimately - each original piece did one thing only) to do what I needed, and I had KPPP execute the final script with an argument saying whether it was "dialing", "connected", or "disconnected" and the script reacted accordingly.

It's hard to write a script for the sake of writing a script - you do need a goal - and if that goal does something that helps you on your machine, it makes it interesting and satisfying to create your own solution.

Browse the programming forum for ideas - look at scripts (even just one-liners) that others have posted, and understand that they're doing. And when someone posts a question in the programming forum, looking for a solution, try to come up with one yourself: create the circumstances they describe (i.e. I have a log file that contains ABC, XYZ, and 123, and I need to....) and practice some ideas to do what they are looking for.

Keep in mind:
Absolute Bash Scripting guide;
TLDP's Bash intro (probably old, but worth a look): http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
Greg's Bash FAQ Wiki: http://mywiki.wooledge.org/BashFAQ

Good luck!

konsolebox 09-24-2010 06:24 AM

Hi. If you like you can also try my shell script based projects. ^_^

PlayShell
Shell Script Loader


All times are GMT -5. The time now is 03:20 AM.