wiki:Documentation/UserGuide/ShellScript

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 clean.sh.

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

emacs ../bin/clean.sh

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

#!/bin/bash
rm -f ../Output/*_history.nc ../Restart/*_out.nc ../bin/output.txt

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

chmod +x clean.sh

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

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):

#!/bin/sh

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

for src in parallel global driver stomate parameters sechiba
do

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

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

done

Another example with a loop

To change the name of multiple files https://forge.ipsl.jussieu.fr/orchidee/wiki/Documentation/UserGuide/ReName

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