So I am trying to make a count-down timer in bash, where I have two files-
One for my alarm functionalities
The other for displaying the numbers on the terminal
So my directory structure is somewhat like this-
Parent Dir
|____ alarm.sh
|____ views.sh
My first attempt was to make a $directory variable and get the path-
directory=$PWD
However, if I execute my script from another directory, it creates an issue, since $directory would be the new directory and not the one the script is in.
I then tried using the readlink command-
path=$(dirname "$(readlink -f "$0")")
. $path/views.sh
This, however, creates problems. While it does work, following links and all, in GNU/Linux bash, it does not in the OSX bash (which I think is BSD, but I may be wrong).
So my basic question is- How to refer to views.sh from alarm.sh? And is there a way to do so without going through the hassle of finding the parent directory name?