How to write a shell script

Author: S.Luyssaert
Last revised: 2020/02/28, P. Maugis; 2020/05/11, A. Ducharne

A super simple script for recurring tasks

We want to make a script that deletes all the history and restart files from ORCHIDEE so that we can run the next simulation within the same file structure with the same starting time. We will call the command

Open an editor for the command file, i.e. ''

emacs ../bin/

Write the linux commands in the editor. Here, we select 'bash' as the shell-interpreter.

rm -f ../Output/* ../Restart/* ../bin/output.txt

Save the file and change the permissions so the file can be executed

chmod +x

You can now type ./ to execute the linux commands from the file ''

An example with a loop

You have installed two versions of ORCHIDEE and you want to compare the sources with diff. This is done by the following script (written for bash):


ref =$workdir/trunkv1/modipsl/modeles/ORCHIDEE

for src in parallel global driver stomate parameters sechiba

 echo '********************'
 echo $ref
 echo $test
 echo DIFF src_$src
 echo '********************'

 cd $ref/src_$src
 for xx in `ls *.f90`
  echo $xx
  diff -r $xx $test/src_$src/$xx
  echo '------------------------'


Another example with a loop

To change the name of multiple files

Last modified 3 years ago Last modified on 2020-05-11T17:26:39+02:00