How do I run a shell?

Karl Hegbloom hegbloom at pdx.edu
Fri Dec 30 11:23:53 UTC 2005


On Thu, 2005-12-29 at 10:53 +0200, Bill Cairns wrote:
> I create a file called dir in bin. The contents of the file is simply one line "ls".

There should be two lines:

#!/bin/sh
ls -l "$@"

or

#!/bin/sh
exec ls "$@"

> I add execute to the file properties.
> I type dir in the terminal window.
> 
> In SuSe I get the listing from the ls.

Odd. I don't know why it works... unless there is a shell alias named
'dir', or a script or command by that name that is earlier in the PATH
than your own script.

> In Ubuntu I get "command not found".

That is due to either one of two reasons.  1, the script may not be on
your PATH, and thus your script is not found.  2, you did not name the
interpreter that should evaluate and apply the script, and so the shell
you type the command in doesn't know what to do with it.

> In Ubuntu, if I type ". dir", it works.

Because you are asking your command line shell to "source" the script.
It's finding it because the script is in your present working directory.
If you 'cd ~' first, it won't work without specifying the full path to
your 'dir' script.

Read about shell aliases and more about shell scripting by finding the
'Guides' at the Linux Documentation Project web site.

-- 
Karl Hegbloom <hegbloom at pdx.edu>





More information about the ubuntu-users mailing list