A simple example:
ryan@C02X43Q9JG5K tmp.kU0KEN9U $ tree .
.
├── fakepaths
│ └── bin
│ └── shell.sh -> ../realpaths/bin/shell.sh
└── realpaths
├── bin
│ └── shell.sh
└── lib
└── shell.lib.sh
5 directories, 3 files
A simple script:
ryan@C02X43Q9JG5K tmp.kU0KEN9U $ cat realpaths/bin/shell.sh
#!/usr/bin/env bash
set -x
realpath="$(cd $(dirname "$0") && pwd)"
[[ -f ${realpath}/../lib/shell.lib.sh ]] &&
echo "found shell lib" ||
echo "no shell lib found!"
And oh no, surprise, it doesn't actually work.
ryan@C02X43Q9JG5K tmp.kU0KEN9U $ ./realpaths/bin/shell.sh
+++ dirname ./realpaths/bin/shell.sh
++ cd ./realpaths/bin
++ pwd
+ realpath=/var/folders/pg/p4vzhf114sx6n2zmf_lz_df00000gn/T/tmp.kU0KEN9U/realpaths/bin
+ [[ -f /var/folders/pg/p4vzhf114sx6n2zmf_lz_df00000gn/T/tmp.kU0KEN9U/realpaths/bin/../lib/shell.lib.sh ]]
+ echo 'found shell lib'
found shell lib
ryan@C02X43Q9JG5K tmp.kU0KEN9U $ ./fakepaths/bin/shell.sh
+++ dirname ./fakepaths/bin/shell.sh
++ cd ./fakepaths/bin
++ pwd
+ realpath=/var/folders/pg/p4vzhf114sx6n2zmf_lz_df00000gn/T/tmp.kU0KEN9U/fakepaths/bin
+ [[ -f /var/folders/pg/p4vzhf114sx6n2zmf_lz_df00000gn/T/tmp.kU0KEN9U/fakepaths/bin/../lib/shell.lib.sh ]]
+ echo 'no shell lib found!'
no shell lib found!
ryan@C02X43Q9JG5K tmp.kU0KEN9U $