Linux - Script (Shebang)

> Operating System - Kernel (Windows, Unix, Linux) > Linux / Unix

1 - About

Script in Linux:

  • can be written in many language
  • does not need an extension
  • must be given the execution permission
Advertising

3 - Syntax (Shebang)

#!/bin/bash 
or
#!/usr/bin/env perl

where the first line called the shebang define the interpreter to run.

  • the # is the command
  • the exclamation mark (“!”) is affectionately called “bang”
  • /bin/bash the path to the interpreter.
  • env start a new script without environment variable

The interpreter is not limited to bash. Scripts can be written in an other language such as:

#!/bin/csh
  • Python,
#!/bin/python
  • Perl
#!/bin/perl
#!/usr/bin/Rscript
  • Ruby, PHP, etc, etc.

The shebang is a kernel required syntax (not mandatory from the shell prespective)

Advertising
os/linux/script.txt · Last modified: 2018/09/16 12:42 by gerardnico