Question: Quite often, the script I want to execute is not located in my current working directory and I don't really want to leave it.

Is it a good practice to run scripts (BASH, Perl etc.) from another directory? Will they usually find all the stuff they need to run properly?

If so, what is the best way to run a "distant" script? Is it

```
. /path/to/script

```

or

```
sh /path/to/script

```

and how to use `sudo` in such cases? This, for example, doesn't work:

```
sudo . /path/to/script

```

Answer: 
I usually do like you say

```
sh /path/to/script

```

And to run it as root/superuser

```
sudo sh /path/to/script

```

Your current directory only matters if the scripts assumes you are in the same folder as it. I would assume most scripts don't do this and you are save to run it like above.
I usually keep my scripts in `/usr/local/bin` or `/usr/local/sbin/` (if the script needs root privileges) where, according to the Filesystem Hierarchy Standard (FHS), they belong.

All you have to do is to make sure these two directories are added to your `PATH`. You can do this by editing your `$HOME/.bashrc` file and adding this line:

```
export PATH=$PATH:/usr/local/sbin:/usr/local/bin

```

If you want to be able to execute a script as root via `sudo`, you have to add these directories to the variable `secure_path` in your `/etc/sudoers`. 

```
Defaults    secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

```

Editing this file is done by running `visudo` which ensures you don't have any mistakes.