AnalyzingData/Primer_ShellScripting - Meg Wiki

Revision 4 as of 2010-06-11 11:24:58

Clear message
location: AnalyzingData / Primer_ShellScripting

You should already know how to set-up and use a [http://imaging.mrc-cbu.cam.ac.uk/imaging/UsingVNC VNC viewer], and have some basic knowledge of [http://www.ee.surrey.ac.uk/Teaching/Unix/ Linux or Unix]. The following is just to get you on the way. Click here, for example, for more on [http://www.freeos.com/guides/lsst/ shell scripting].

For example, you probably know commands such as ls, cd, pwd or mkdir which you usually execute in a command window:

attachment:FirstCommands.jpg

If you want to display text on the screen, you can use the "echo" command. If you want to display this text very often (don't ask for the reason), then you can write it in a script.

Open a new file (e.g. using the text editor "nedit", put "#!/bin/sh" at the top (so the file knows it's a script and how to interpret the following commands), and add the command you would like execute.

Save the file. You have to make the file executable by changing the permissions ("chmod" command).

attachment:FirstScript.jpg

This is boring. You want to be more flexible. In many scripts, you want to execute the same command(s) for a number of different subjects. For this, there is the "for" loop:

attachment:LoopScript.jpg