Skip to content

What is a bash script

Jean-Michel Gigault edited this page Jan 8, 2015 · 21 revisions

What is a bash script

A bash script is a simple file that contains ASCII text intended to be interpreted by the program bash, allowing you to do a logical sequence of actions by calling a simple line command instead of typing them one at a time in the shell.

The first line of a script should always tell the shell which program should interpret it:

#!/bin/bash
echo "Hello World, I am a 42 student!"

In our case, the script should be interpreted by /bin/bash and say Hello if it is invoked.

To invoke a script, you can type sh scriptname or make it executable with a chmod and call it with its name:

e1r1p1$ chmod 755 scriptname
e1r1p1$ ./scriptname

Introduction:

Bash syntax:

Bash tools:

  • Builtin commands
  • Awk
  • Cat
  • Grep
  • Sed

Bash sample codes:

Clone this wiki locally