Last active
October 7, 2025 21:37
-
-
Save alifarazz/83706a888806589812c6ef97946ad4bf to your computer and use it in GitHub Desktop.
Get path of the currently running script in BASH. Also supports SLURM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # Get path to current script, | |
| if [ -n "${SLURM_JOB_ID:-}" ] ; then | |
| SCRIPT_PATH="$(scontrol show job "$SLURM_JOB_ID" | awk -F= '/Command=/{print $2}')" | |
| else | |
| SCRIPT_PATH="$(readlink -f "${BASH_SOURCE[0]}")" | |
| fi | |
| SCRIPT_DIR="$(dirname "${SCRIPT_PATH}")" | |
| echo "$SCRIPT_PATH" | |
| echo "$SCRIPT_DIR" | |
| # source: https://stackoverflow.com/a/56991068 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment