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

<<   >>
The dot

Why do I have to prefix the program with "./" to run it, sometimes, and sometimes not?

  dlink@viddev1> hello.sh
  -bash: hello.sh: command not found

  dlink@viddev1> ./hello.sh
  Hello, World.

It has to do with your PATH environment variable.

Let's look at the value of $PATH:

  dlink@viddev1> echo $PATH
  /usr/local/qt/bin:/usr/local/pgsql813/bin:/home/dlink/bin:/usr/local
  /bin:/usr/bin:/usr/X11R6/bin:/bin:/usr/games:/opt/gnome/bin:/opt/kde
  3/bin:/usr/lib/java/jre/bin:/usr/local/bin:/home/dlink/bin:/opt/gnom
  e/bin:/home/dlink/video/bin:/home/dlink/globalvideo/bin

The shell searches for the program in each of the (colon separated) subdirectories listed.

One nice way to examine the $PATH is to replace colons with carriage returns:

  dlink@viddev1> echo $PATH | tr ':' '\n'
  /usr/local/qt/bin
  /usr/local/pgsql813/bin
  /home/dlink/bin
  /usr/local/bin
  /usr/bin
  /usr/X11R6/bin
  /bin
  /usr/games
  /opt/gnome/bin
  /opt/kde3/bin
  /usr/lib/java/jre/bin
  /usr/local/bin
  /home/dlink/bin
  /opt/gnome/bin
  /home/dlink/video/bin
  /home/dlink/globalvideo/bin

Where am I?

  dlink@viddev1> pwd
  /home/dlink/public_html/bash_scripting

Oh, and that subdirectory is not in the $PATH list.

That is why it does not work when i don't use the ./ !

The dot (.) is actually just a relative path to the file.

The dot (.) means current working directory.

Dot dot (..) means the parent directory.


You can add the dot (.) to your PATH if you like:

  dlink@viddev1> PATH=".:$PATH"
  dlink@viddev1> echo $PATH | tr ':' '\n'
  .
  /usr/local/qt/bin
  /usr/local/pgsql813/bin
  /home/dlink/bin
  /usr/local/bin
  /usr/bin
  /usr/X11R6/bin
  /bin
  /usr/games
  /opt/gnome/bin
  /opt/kde3/bin
  /usr/lib/java/jre/bin
  /usr/local/bin
  /home/dlink/bin
  /opt/gnome/bin
  /home/dlink/video/bin
  /home/dlink/globalvideo/bin
  dlink@viddev1> hello.sh
  Hello, World.

  dlink@viddev1> ./hello.sh
  Hello, World.