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: 
Say you want to run `./script` and the path is `/home/test/stuff/`

But the path you're currently in is `/home/test/public_html/a/`

Then you would need to do `../../stuff/./script`

Which goes back 2 folders, then into into the folder there and run the script.
It's better to modify your script to use its absolute path before addressing any relative files.

Of course for scripts we can do it conveniently and flexibly by keeping the [`dirname`](https://linux.die.net/man/1/dirname) of the script in a variable before-hand.

For example, change:

```
cat needed_file

```

to:

```
SCRIPT_PATH=$(dirname "$0")
cat "${SCRIPT_PATH}/needed_file"

```