Last active
January 11, 2022 11:52
-
-
Save kou1okada/24a76e5ff5eaac0ba43282fcc0d4c7f5 to your computer and use it in GitHub Desktop.
run_once.bash - run command only once
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 | |
# | |
# run_once.bash - run command only once | |
# Copyright (c) 2019 Koichi OKADA. All right reserved. | |
# This script distributed under the MIT license. | |
# | |
function run_once () # [<command> [<args> ...]] | |
# Run [<command> [<args> ...]] only once. | |
# Return: | |
# Return exit status which was returned first time call for [<command> [<args> ...]]. | |
{ | |
declare -gA RUN_ONCE | |
declare -n retval=RUN_ONCE[$(IFS=$'\x1c'; printf "%s" "$*")] | |
[ -z "$retval" ] && { "$@"; retval=$?; } | |
return $retval | |
} | |
[ "$(readlink -f -- "$0")" = "$(readlink -f -- "$BASH_SOURCE")" ] && echo "Usage: source run_once.bash" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment