Created
November 26, 2020 03:18
-
-
Save gildas/382b096f7270935e47d04a8c8b282b21 to your computer and use it in GitHub Desktop.
Revisions
-
gildas created this gist
Nov 26, 2020 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ #!/usr/bin/env bash function main() { local APPEND=0 while (( "$#" )); do # Replace --parm=arg with --parm arg [[ $1 == --*=* ]] && set -- "${1%%=*}" "${1#*=}" "${@:2}" case $1 in -a|--append) APPEND=1 ;; esac shift done # Set all positional arguments back in the proper order eval set -- "${ARGS[@]}" out=$1 temp=$(mktemp "${out%%/*}/tmp-sponge.XXXXXXXX") && cat > "$temp" && if (( APPEND )) then cat "$temp" >> "$out" else if [[ -f $out ]]; then chmod --reference="$out" "$temp" mv "$temp" "$out" elif [[ -n $out ]]; then cat $temp > $out else cat $temp fi fi && rm -f "$temp" } main "$@"