<?xml version="1.0" encoding="utf-8"?><!DOCTYPE article  PUBLIC '-//OASIS//DTD DocBook XML V4.4//EN'  'http://www.docbook.org/xml/4.4/docbookx.dtd'><article><articleinfo><title>AnalyzingData/Primer_ShellScripting</title><revhistory><revision><revnumber>22</revnumber><date>2013-03-08 10:02:29</date><authorinitials>localhost</authorinitials><revremark>converted to 1.6 markup</revremark></revision><revision><revnumber>21</revnumber><date>2012-04-13 12:42:38</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>20</revnumber><date>2010-12-09 19:32:38</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>19</revnumber><date>2010-09-09 10:26:03</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>18</revnumber><date>2010-07-16 16:46:12</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>17</revnumber><date>2010-07-16 16:35:13</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>16</revnumber><date>2010-07-16 14:19:56</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>15</revnumber><date>2010-07-16 14:17:20</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>14</revnumber><date>2010-07-16 14:15:31</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>13</revnumber><date>2010-07-16 14:13:05</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>12</revnumber><date>2010-07-16 14:10:32</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>11</revnumber><date>2010-06-15 14:47:07</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>10</revnumber><date>2010-06-11 13:27:25</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>9</revnumber><date>2010-06-11 13:26:52</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>8</revnumber><date>2010-06-11 13:20:42</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>7</revnumber><date>2010-06-11 11:29:36</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>6</revnumber><date>2010-06-11 11:26:31</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>5</revnumber><date>2010-06-11 11:25:20</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>4</revnumber><date>2010-06-11 11:24:58</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>3</revnumber><date>2010-06-11 11:20:45</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>2</revnumber><date>2010-06-11 11:13:19</date><authorinitials>YaaraErez</authorinitials></revision><revision><revnumber>1</revnumber><date>2010-06-11 11:07:43</date><authorinitials>YaaraErez</authorinitials></revision></revhistory></articleinfo><section><title>A Quick Primer on Linux and Shell Scripting</title><para>You are assumed to know how to set-up and use a <ulink url="http://imaging.mrc-cbu.cam.ac.uk/imaging/UsingVNC">VNC viewer</ulink>, and have some basic knowledge of <ulink url="http://www.ee.surrey.ac.uk/Teaching/Unix/">Linux or Unix</ulink> (see e.g. our <ulink url="http://imaging.mrc-cbu.cam.ac.uk/methods/unixsurvivalguide">unix survival guide</ulink>). The following is just to get you on the way. Click here, for example, for more on <ulink url="http://www.freeos.com/guides/lsst/">shell scripting</ulink>. </para><para><anchor id="anchortricks"/> </para><section><title>Some Practical Tricks...</title><itemizedlist><listitem><para>You can get <emphasis role="strong">help</emphasis> on almost any Linux command typing &quot;man command&quot;, e.g. &quot;man rm&quot;. </para></listitem><listitem><para>You can use the cursor keys &quot;Up&quot; and &quot;Down&quot; to <emphasis role="strong">scroll through your recent Linux commands</emphasis> (and re-use or modify them). </para></listitem><listitem><para>typing &quot;history&quot; shows you the <emphasis role="strong">list of your recent commands</emphasis> </para></listitem><listitem><para>If you start typing (e.g. &quot;matl&quot;) and then press the &quot;tab&quot; key, Linux will <emphasis role="strong">complete</emphasis> to the next uniquely identifyable command (i.e. &quot;matlab&quot; in the example). </para></listitem><listitem><para>The same holds for file names: type &quot;ls myfilen&quot; and then &quot;tab&quot; may <emphasis role="strong">complete</emphasis> to something like &quot;ls myfilename.txt&quot; (unless there are also other files with exactly the same beginning) </para></listitem><listitem><para>If you want the <emphasis role="strong">output of a command in a text file</emphasis>, you can use the &quot;&gt;&quot; symbol. For example, &quot;ls * &gt; filelist.txt&quot; will write the contents of your current directory to the file filelist.txt. &quot;&gt;&quot; overwrites, &quot;&gt;&gt;&quot; appends. </para></listitem><listitem><para>You can <emphasis role="strong">copy&amp;paste</emphasis> in Linux: Mark something by moving the cursor over some text while holding the left mouse button pressed. Then click the mouse wheel (or middle button). The marked text should appear where you last left the cursor (e.g. command window or text editor). </para></listitem><listitem><para>Sometimes you may have problems executing scripts that were created as text files in Windows - if in doubt, use &quot;dos2unix&quot; to convert these files to unix code (e.g. &quot;dos2unix -o myfile.txt&quot;). </para></listitem></itemizedlist></section><section><title>Basics of Linux</title><para>You probably already know commands such as ls, cd, pwd or mkdir which you usually execute in a command window: </para><para><inlinemediaobject><imageobject><imagedata fileref="https://lsr-wiki-02.mrc-cbu.cam.ac.uk/meg/AnalyzingData/Primer_ShellScripting?action=AttachFile&amp;do=get&amp;target=FirstCommands.jpg"/></imageobject><textobject><phrase>FirstCommands.jpg</phrase></textobject></inlinemediaobject> </para><para>See below for some <link linkend="anchortricks">tricks</link> that may be useful when you work with Linux a lot. </para></section><section><title>Basics of Shell Scripting</title><para>If you want to display text on the screen, you can use the &quot;echo&quot; command. If you want to display this text very often (don't ask for the reason), then you can write it in a script. </para><para>Open a new file (e.g. using the text editor &quot;nedit&quot;), put &quot;#!/bin/sh&quot; 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. </para><para>Save the file. You have to make the file executable by changing the permissions (&quot;chmod&quot; command). </para><para><inlinemediaobject><imageobject><imagedata fileref="https://lsr-wiki-02.mrc-cbu.cam.ac.uk/meg/AnalyzingData/Primer_ShellScripting?action=AttachFile&amp;do=get&amp;target=FirstScript.jpg"/></imageobject><textobject><phrase>FirstScript.jpg</phrase></textobject></inlinemediaobject> </para><para>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 &quot;for&quot; loop: </para><para><inlinemediaobject><imageobject><imagedata fileref="https://lsr-wiki-02.mrc-cbu.cam.ac.uk/meg/AnalyzingData/Primer_ShellScripting?action=AttachFile&amp;do=get&amp;target=LoopScript.jpg"/></imageobject><textobject><phrase>LoopScript.jpg</phrase></textobject></inlinemediaobject> </para><para>Nothing can stop you now! </para></section></section></article>