AnalyzingData/Primer_ShellScripting - Meg Wiki

Upload page content

You can upload content for the page named below. If you change the page name, you can also upload content for another page. If the page name is empty, we derive the page name from the file name.

File to load page content from
Page name
Comment
WHat wOrd is made by the captiaL lettErs?

Revision 10 as of 2010-06-11 13:27:25

location: AnalyzingData / Primer_ShellScripting

A Quick Primer on Shell Scripting in Linux

You are assumed to 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].

You probably already 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

Nothing can stop you now!