Last active
June 17, 2022 23:07
-
-
Save andres-fr/2a69d43a97b3d71fba66b6f355b85b94 to your computer and use it in GitHub Desktop.
Example of a bash function with named parameters+defaults
This file contains 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
interactive_gpu() | |
{ | |
# needed by getopt: https://stackoverflow.com/a/5048356 | |
local OPTIND | |
# default parameter values | |
seconds=300 | |
partition="large" | |
# parse flags to optionally override param defaults | |
while getopts "p:t:" f; do | |
case "${f}" in | |
p) | |
partition=${OPTARG} | |
;; | |
t) | |
seconds=${OPTARG} | |
;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
# parameter transformations, when needed | |
timestamp=$(date -d@${seconds} -u +%H:%M:%S) # convert seconds to hh:mm:$ | |
# print and execute main call | |
cmd="srun --partition=${partition} --nodes=1 --ntasks-per-node=1 --cpus-per-task=8 --mem=45GB --gres=gpu:1 --time=${timestamp} --pty bash -i" | |
echo $cmd | |
eval "$cmd" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment