Quote:
Originally Posted by ryanbrimmer
I actually want the script automated, not manual. How did you learn this stuff? Just experience? I have had my head in books and online tutorials for weeks now, and it just won't click.
|
Cool to hear Tink's helped you out - I'm not remotely a whiz myself but maybe something in all this will also help.
In the simplest sense, a shell script just a file that's been chmod'ed executable, has '#!/bin/sh' as its preamble, and is just a list of commands after that - a 'batch file' of commands that can be just as you'd type them in at the command line, only wrapped up in a single simple invocation. Then you can get a
lot more elaborate from there.
To take my usual shell, the bash manual page lists about half a dozen metacharacters, about a half-dozen more control operators, and a few reserved words. (! case do done elif else esac fi for function if in select then until while { } time [[ ]])
It then describes simple commands, pipelines, lists, and compound commands, which include many of the reserved words and control flow constructs (if, for, while, case).
You learn about these and quoting and the various expansions and substitutions (brace, tilde, parameter, command, arithmetic, process, pathname) and learn about redirection, functions, conditional expressions, and signals and you've basically got it covered.
The
real trick is learning the shell builtins
and standard external *nix commands to actually harness all their power. The shell scripting framework itself is not too bad. As an infodump, it sounds like a lot, but it's not too terribly many pieces (maybe a dozen or two from a certain way of counting) and if you just break it down to those pieces and take things a step at a time, you'll get it.
So I recommend using the command line as your standard interface (excluding web browsing and image editing and the like, of course - though a lot can be done with that there, too) so you get familiar with all the tools at your disposal (by using them and reading their manual pages). If you don't tend to use the CLI utilities regularly it's going to be like a strange incomprehensible universe but, if you're familiar with them, it's just a case of getting your familiar troops lined up and making them march. And then reading some scripting book straight through just to get a lay of the land and sort of break the ice on what can be a somewhat cryptic manual page at first, and then tear into your shell's manual page, itself. And practice. And re-read the manual page. But everybody has their own learning methods, so just keep experimenting until you find something that works for you. Maybe you're actually reading dry abstractions
too much and need to do more of the hands-on practice. Either way - good luck.