Last active
December 20, 2023 10:30
-
-
Save gintenlabo/a09343702b790dc898b981db0ca45cc6 to your computer and use it in GitHub Desktop.
与えられた各引数をエスケープした上でスペース区切りで出力する関数
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
#!/usr/bin/env bash | |
set -ueo pipefail | |
SEPARATOR=${SEPARATOR:- } | |
TRAILING_SEPARATOR=${TRAILING_SEPARATOR:-} | |
quote_each_args() { | |
for i in $(seq 1 $#); do | |
printf '%q' "${!i}" | |
if [[ $i -lt $# ]]; then | |
printf '%s' "${SEPARATOR}" | |
else | |
printf '%s' "${TRAILING_SEPARATOR}" | |
fi | |
done | |
} | |
# usage | |
print_command() { | |
echo "command: '$(quote_each_args "$@")'" | |
} | |
print_command rm -f 'file with space' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment