Skip to content

Scripting with the commando shell

Scripting via commando shell can be done in every operation system (Windows, Mac, Linux, etc...). In this tutorial we will focus on script for linux, however shell-scripts for other operation systems follow the same principle (there can be syntex-differences).

Here is a basic script with evaluates the deformation of a cantilever on different planets:

#!/bin/bash -i

#Loop through the planets
for planet in 'Moon' 'Earth' 'Mars' 'Jupiter';
  #Set default gravity value

  #Print out on which planet we are
  echo Simulationon $planet

  #Set gravity according to planet
  if [ $planet = 'Moon' ]; then
  elif [ $planet = 'Earth' ]; then
  elif [ $planet = 'Mars' ];then
  elif [ $planet = 'Jupiter' ]; then

  #Print out the used gravity
  echo with gravity $gravity m/s^2

  #Create Simulation-name

  #Search in template-file for GRAVITY and replace it with $gravity and save it under $job'.xml'
  sed 's/GRAVITY/'$gravity'/g' simulation_template.xml > $job'.xml'

  #Simulate with openCFS
  #if unsure where cfs is located use the command "type cfs"
  /path/to/cfs $job

Be caution with spaces in shell-scripts! Its a syntax error!

General convention is that shell-scripts are saved with a .sh ending, like

Running the script

Run the script in the terminal either via the bash-command


or execute it directly with


but be aware that in this case you must made the script executable with

chmod +x

Example and Tutorial Suggestion

Here is a small example for downloading. Just unzip it and run the script in the terminal command and see what happens.

Try to:

  • Add more planets
  • Modify the placeholder string GRAVITY to G and ajust the template and the script accordingly
  • Hint: Be careful with spaces, use the exact syntax as shown