Perl problems

ZIYAD A. M. AL-BATLY zamb at
Thu May 12 10:43:40 UTC 2005

On Wed, 2005-05-11 at 22:49 -0400, Stephen R Laniel wrote:
> On Wed, May 11, 2005 at 10:38:28PM -0400, mohaham wrote:
> > sh names.txt
> Correct me if I'm wrong, but if that works and just typing
> '' doesn't, then there's something rather
> odd/serious wrong with his setup. The shell should already
> 1) open the file,
> 2) spot the '#!"
> 3) run the script with the program specified after the '#!'
> If it doesn't do so, that's odd.
No it's not.  Unlike DOS/Windows, in Unix and compatible (like Linux,
FreeBSD) the way to find a command to execute goes like this:
     1. Is it a command that leads to an absolute *executable* file?  If
        yes, run that file.  Examples: /usr/bin/time, /usr/bin/test,
        assuming you are in "/usr": bin/gedit, still assuming you're in
        "/usr": ../bin/dir.
     2. Is the command you typed is an "alias"?  If yes, expand this
        alias and start again with the expanded data.  (To see your
        current alias(s), type "alias".  See the bash manual (man bash)
        and read more about alias.)
     3. Is it a shell built-in?  If yes, run that (no new process will
        be created as the shell is already running).  Examples are: ls,
        cd, time, test.  See "man bash" for more built-in(s).
     4. Search the directories listed in the environment variable PATH
        (try: echo $PATH) from left to right, and try to find an
        *executable* with the name you typed.  If found, run it.

And that's it!  So, when you type "", nothing happens, which
to be expected.  Why?
     1. To start with, it's not an executable (you need to do "chmod +x" to make it executable).
     2. You didn't supply a command that can lead to a file (no, being
        in the same directory as the executable doesn't count (but see
        point 3 below)).  This is why Some replies told him/her to type
        "./", which lead to the file directly (it's in this
        directory "./", and it's name is").
     3. The current directory is not on your PATH variable.  And by the
        way, add your current directory to the PATH variable is a very
        big security risk!  Only add *absolute* directory names only!
     4. There is no shell built-in with the name "".
     5. When the others said do "sh secede2.p name.txt", what really
        happend is that you run/execute the "sh" and pass to it
        " name.txt" as variables.  "sh", in turn, will check
        the first line of "" and see the "#!/usr/bin/perl" and
        will execute that application and pass to it "name.txt" as
        variable.  This why you don't need "" to be executable
        in this case, and you don't need to till "sh" it's as "sh", by
        default, will search *only* in the current directory.

I hope this helps.

More information about the ubuntu-users mailing list