Get the path of the script

ref:  https://developpaper.com/bash-tips-01-get-the-scripts-own-path/


my_path=$(cd $(dirname "BASH_SOURCE[0]") && pwd)



https://www.ostricher.com/2014/10/the-right-way-to-get-the-directory-of-a-bash-script/

itamar@legolas ~ $ cat foo.sh
echo "$0"
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
echo "$SCRIPT_DIR"
itamar@legolas ~ $ ./foo.sh
./foo.sh
/Users/itamar
itamar@legolas ~ $ cd foobar/
itamar@legolas foobar $ ./../foo.sh
./../foo.sh
/Users/itamar

Comments

Popular posts from this blog

Fixing the DeepSpeed Import Error While Fine-Tuning the Qwen Model

Amazon Linux 2023 - User data configuration for launch templates to connect to the EKS cluster

How to create ISM policy and rotate logs in opensearch