Bash Shell Scripting
Crash Course
crowfly.net

<<   >>

Introduction

GNU_Tools

Example1

Example2

Execution_bit

Bang_bin_bash

Example3

The_dot

Example4

Example5

Example6

Example7

Example8

Background

Forking

Example9

Bash_profile

Pattern_match

Regex

Debug

Gory_details

References

<<   >>
Setting the Execution bit on a file

In order to run a script in Unix you need to set the execution bit:

Say I just created the talk.sh script shown in Example 2.

  dlink@viddev1> emacs talk.sh
  dlink@viddev1>
Note on Unix Text Editors: You can choose from vi, emacs, pico, or joe to name some of the common ones. This is one of every Unix newbie's great hurdle -- learning a new Text Editor.

  dlink@viddev1> ls -l talk.sh
  -rw-rw-r--   1 dlink viddev    5 2006-07-20 13:10 talk.txt

Now to set the execution bit:

  dlink@viddev1> chmod a+x talk.sh
  dlink@viddev1> ls -l talk.sh
  -rwxrwxr-x   1 dlink viddev    5 2006-07-20 13:10 talk.sh

Meaning of the three x's:

  • Executable for the owner (that's me),
  • Executable for any user in my group: viddev, and
  • Executable for all other, respectively.

Another way to set the execution bits, (which is cooler because it uses binary) is this:

  dlink@viddev1> chmod 775 talk.sh
  dlink@viddev1> ls -l talk.sh
  -rwxrwxr-x   1 dlink viddev    5 2006-07-20 13:10 talk.sh

Finally we're good to go:

  dlink@viddev1> ./talk.sh
  Hello dlink,
  Today is Thursday
  Today's date is 20-Jul-2006
  And the time is 11:51:59 AM

But what if I don't want to set the Execution bit?

Fine, you would get this:

  dlink@viddev1> ./talk.sh
  -bash: ./talk.sh: Permission denied