I have a bash script located in /home/http/mywebsite/bin/download.sh

I have a config file in /home/http/mywebsite/config/config.yaml

Now I want to read the yaml file no matter where I execute my script.

The problem:
When I cd into /home/http/mywebsite/bin/ and run ./download.sh everything works.

When I cd into /home/ and run http/mywebsite/bin/download.sh it can not find the config file because of the relative path.

How do I make sure I can always read the config file no matter where I execute the script. It is always located 4 directories up from the script in config/config.yaml

The script looks like this:

```
#!/bin/bash
# This will give me the root directory of my project which is /home/http/mywebsite/
fullpath="$( cd ../"$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cat ${fullpath}config/config.yaml

```

This works if I execute it inside the directory where the script is.

If I execute the script from another directory such as /home/ I get the following error:

```
cd: ../http/mywebsite/bin: No such file or directory
cat: config/config.yaml: No such file or directory

```

Solution?

If it is possible it would be great with a code snippet that can traverse up a path N amount of times, this would solve my problem. But it is too advanced for me.

For example you can set a variable "cd\_up=1" how many times to go up. The run the loop/sed or whatever magic.

And it would turn the absolute string from:
/home/http/mywebsite/bin/
into:
/home/http/mywebsite/

And changing it to 2 it would change the string to:
/home/http/