2

How can I run a program without cd'ing to the directory where it resides?

I have tried ./my/dir myfile.pl and again without the leading . but neither work.

6

You enter the full path of the executable:

./path/to/my/dir/myfile.pl
  • The file will still be ran from the directory you are currently in. keep that in mind. – UtahJarhead Oct 3 '12 at 18:15
-2

Two dots solves the problem, one dot generates an error (on debian at least) as in the example below:

../usr/local/bin/myprogram

  • 1
    Two dots do not 'solve the problem'. The dot refers to the current directory, two dots refer to the parent; they are different paths, one of which may or may not be the one you seek. Depending on the current directory, your example may work, but I believe you're looking for the more general /usr/local/bin/myprogram. – Marcks Thomas Nov 18 '13 at 14:57
  • 1
    whatever directory i am in, one dot 'generates a bash' error! – BurakT Nov 18 '13 at 15:38

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.