Loading ...
Sorry, an error occurred while loading the content.
 

Running an executable from an outside directory

Expand Messages
  • baum_j
    Group hello, I have a one line batch file, with its mode set to executable. The file runs fine when typing its name through the shell - in its proper
    Message 1 of 2 , May 14, 2009
      Group hello,

      I have a one line batch file, with its mode set to executable.
      The file runs fine when typing its name through the shell - in its proper directory.
      So, if for example the file is:
      /home/david/dir/runme
      then:
      ~/dir $ runme
      Will successfully run the file.

      However:
      ~/otherDir $ /home/david/dir/runme
      Won't work.

      Why is that?
      How can this be fixed.
      I do not wish to copy the batch file to the /usr/bin directory. It is a stupid shortcut command, that on the long run has no business on wither /usr/bin, or /bin directories.

      David
    • Shlomi Fish
      ... They are not called batch files in UNIX. They are called shell scripts. And shell scripts need to have the sha-bang at the beginning ( #!/bin/sh ,
      Message 2 of 2 , May 15, 2009
        On Friday 15 May 2009 04:46:13 baum_j wrote:
        > Group hello,
        >
        > I have a one line batch file, with its mode set to executable.

        They are not called "batch files" in UNIX. They are called shell scripts. And
        shell scripts need to have the sha-bang at the beginning ("#!/bin/sh" ,
        "#!/bin/bash", etc.) to be properly executable. Although sometimes it may work
        without it.

        > The file runs fine when typing its name through the shell - in its proper
        > directory. So, if for example the file is:
        > /home/david/dir/runme
        > then:
        > ~/dir $ runme
        > Will successfully run the file.

        Generally, putting "." (= the current working directory) in the PATH or
        otherwise allowing one to run executables from there is dangerous, because
        someone may hijack it to put malicious executables in your current location.
        The PATH should only have fully-qualified paths.

        What does "echo $PATH" in the shell is telling you?

        >
        > However:
        > ~/otherDir $ /home/david/dir/runme
        > Won't work.
        >

        What error does the shell emit?

        > Why is that?

        What does "ls -l /home/david/dir/runme" and then "cat /home/david/dir/runme"
        tell you?

        > How can this be fixed.
        > I do not wish to copy the batch file to the /usr/bin directory. It is a
        > stupid shortcut command, that on the long run has no business on wither
        > /usr/bin, or /bin directories.

        Indeed.

        Regards,

        Shlomi Fish

        --
        -----------------------------------------------------------------
        Shlomi Fish http://www.shlomifish.org/
        Parody on "The Fountainhead" - http://xrl.us/bjria

        God gave us two eyes and ten fingers so we will type five times as much as we
        read.
      Your message has been successfully submitted and would be delivered to recipients shortly.