3.6. Scripts

A script is a file that contains commands. When you run the script, the commands are performed.

The first line of a script should give the command interpreter to use. If you want your script to be read by the bash command interpreter, the first line should be

  #!/bin/bash
To use the sh command interpreter (often used for scripts), use first line
  #!/bin/sh


Parameters

A script can use command-line parameters. Write $1 to refer to the first parameter, $2 to the second, etc. For example, suppose that the following is stored in a file called show.

  #!/bin/sh
  echo $1
  cd $1
  ls
Then command
  show 3300
will write
  3300
  …
where the … part is a listing of what is found in directory 3300. That is very similar to what is done by command
  ls 3300