This is a collaborative space. In order to contribute, send an email to maximilien.chaumon@icm-institute.org
On any page, type the letter L on your keyboard to add a "Label" to the page, which will make search easier.

Create a linux script

Prerequisite

You need to automate something highly repetitive with files in linux.

Goal of this tutorial

Learn how to create a text file and make it executable in a unix (i.e. linux or Mac) environment.

Step-by-step guide

  1. Create an empty text file
  2. Copy-paste the script in it, and save.
  3. Make the file executable
  4. Execute it.
  5. Pass arguments to a script.
A lot of the time, the script you are willing to use exists in /usr/cenir/scripts. Try to find it there first!

Create an empty text file

Open a terminal, change to a directory of interest and type gedit <enter>. This opens a "notepad-like" window in which you can enter text.

Copy-paste a script in it

This can be a script found anywhere on this site or on the www. It usually starts with a line like #!/bin/bash

Save the file (Ctrl+S). Give it the name you like (your_file_name below).

Make the file executable

Enter the following in the terminal

chmod +x your_file_name

chmod stands for "change mode".

Execute it

in the terminal, type

./your_file_name

The "./" at the beginning is the path to your file. "." in linux language often means "here", that is the directory you are in right now (aka current directory).

If you want to run this script from elsewhere, type the full path of the file. For instance:

/home/yourusername/scripts/your_file_name

Pass arguments to a script

Any script can take "arguments". These are passed as a space-separated list, as follows:

./your_file_name file.fif option1

"file.fif" and "option1" are the two arguments here.