Handling Absolute Paths Correctly in Makefile and Shell
Contents
Handling Absolute Paths Correctly in Makefile and Shelllinuxshell
Handling absolute paths in Makefile and shell (mainly Bash).
Copyright notice: This is an original article by xwi88, licensed under CC BY-NC 4.0. Commercial use is prohibited; please cite the source when reposting. Follow at https://github.com/xwi88
Makefile
make version:
3.81
BASEDIR = $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
| |
Linux Shell
Bash version:
5.1
DIR=$(cd $(dirname $0) && pwd)DIR=$(cd $(dirname $0); pwd)DIR=$(cd dirname $0; pwd)DIR=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)ROOT_DIR="${DIR##*/}"FILE_NAME=$(basename "$0")
Warning
BASH_SOURCE only works where a bash shell is available
cat /etc/shellslists the shells supported on this machine
Example
For working examples of the above, see: docker-compose-resources