MLUG Bash Scripting Workshop 25/04/08
Prev Index Next

What makes a Bash script a Bash script?

This isn't official, just my opinion and I didn't think about it too long.

  1. The script would need to have it's permission set so someone can run it.

  2. The first line must begin with the two characters "#" and "!". This is sometimes referred to as the "shebang".

    Since files are seen by programs as streams of data, a method is required to determine the format of a particular file within the filesystem. Different operating systems have traditionally taken different approaches to this problem.*   In the case of Unix, " #! " will tell the kernel to treat the file as an executable script and not a machine code program.

  3. Immediately following the shebang will be the path to the interpreter, for example: #!/bin/bash. It is possible to include options in this first line too, for example: #!/bin/bash -x which would have each command printed before it is executed.

  4. I suppose we could expect that a fourth condition must be met, i.e. there should be some reason or purpose for writing the script.

Next I will briefly about editors and then we'll look at something that I thought warranted the time and effort required to write a script.

*Note: Microsoft's DOS used the three characters following the last full stop (period) of the file name to indicate file type. An executable binary ended in .exe. The DOS equivalent of a script was a batch file and the file extension was .bat. I believe this is also the case through to Windows XP. .


Top