PDA

View Full Version : Shell Scripting


gantww
May 11th, 2007, 09:18 AM
Hello all,
As I continue converting over to Linux, I've begun finding that some of my skills are not yet up to par. In particular, I would like to improve my lack of skills in shell scripting. Does anyone know of any good tutorials or books on the subject?

Thanks,
Will

johnnymac
May 11th, 2007, 09:24 AM
Here's one...

http://www.freeos.com/guides/lsst/

Stephen Howard
May 11th, 2007, 09:42 AM
Try the advanced bash scripting guide (http://tldp.org/LDP/abs/html/). There's also a couple of useful sites like Shelldorado (http://www.shelldorado.com/) (click on the tutorial link for a bunch of options) and the Unix Grymoire (http://www.grymoire.com/Unix/index.html).

Stephen Howard
May 11th, 2007, 09:45 AM
Also try Bash by Example (http://www-128.ibm.com/developerworks/library/l-bash.html) by Daniel Robbins (of IBM and Gentoo fame).

yaaarrrgg
May 11th, 2007, 09:48 AM
Part of shell scripting is just knowing what commands are available on your system. a short list is at:

http://www.linuxdevcenter.com/linux/cmd/

Any list of commands is a shell script. grep, cut, sed and awk are text manipulation tools that are fairly handy. Also, embedding one command in another with backticks `` or $() is extremely useful at times. Another handy trick: you can pipe output from one command to another with |.

You can do more advanced scripting (with if-then-else conditionals, for example). Here's a couple pages I liked:

http://www.esscc.uq.edu.au/~ksteube/Bshell/
http://www.faqs.org/docs/Linux-HOWTO/Bash-Prog-Intro-HOWTO.html#s1

... but if the script starts to feel like an application or starts getting complex, I'd recommend just switching to another programming language like Perl, Python, Ruby, for example. Trying to do complex tasks in Bash is painful. Bash scripts should be simple, so not knowing much about shell scripting isn't necesarilly a bad thing. :)

Stephen Howard
May 12th, 2007, 07:50 AM
Also have a look at the boot scripts is /etc/rc.d to see some examples. They offer the advantage of showing the programming choices of different script authors.

FuturePast
May 12th, 2007, 12:12 PM
And if you really want to get stuck in try the O'Reilly book "Classic Shell Scripting".