aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/%HOME%/.bash_utils
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2017-04-14 22:58:55 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2017-04-14 22:58:55 +0300
commit0289b7cebcfbaafacd90a782332f36122b50495d (patch)
tree2638f19aad12830d9c0f1f230c96b70abea30ede /%HOME%/.bash_utils
parentsums_update_distr: include archives (diff)
downloadlinux-home-0289b7cebcfbaafacd90a782332f36122b50495d.tar.gz
linux-home-0289b7cebcfbaafacd90a782332f36122b50495d.zip
sums_list_paths: handle special characters
Diffstat (limited to '')
-rw-r--r--%HOME%/.bash_utils/distr.sh27
1 files changed, 18 insertions, 9 deletions
diff --git a/%HOME%/.bash_utils/distr.sh b/%HOME%/.bash_utils/distr.sh
index fe44e75..2f51a96 100644
--- a/%HOME%/.bash_utils/distr.sh
+++ b/%HOME%/.bash_utils/distr.sh
@@ -17,10 +17,10 @@ sums_list_paths() (
shift
case "$key" in
-h|--help)
- echo "usage: ${FUNCNAME[0]} [-h|--help] [-0|-z]"
+ echo "usage: ${FUNCNAME[0]} [-h|--help] [-0|--null|-z|--zero]"
return 0
;;
- -0|-z)
+ -0|-null|-z|--zero)
fmt='%s\0'
;;
*)
@@ -33,15 +33,24 @@ sums_list_paths() (
[ -e "$sums_path" ] || return 0
local -a paths=()
-
- local path
- while IFS= read -r path; do
+ local sum path
+
+ while IFS= read -d ' ' -r sum; do
+ local escaped=
+ if [ "${sum#'\'}" != "$sum" ]; then
+ escaped=1
+ sum="${sum:1}"
+ fi
+ IFS= read -r path
+ path="${path#'*'}"
+ if [ -n "$escaped" ]; then
+ path="${path//'\\'/$'\\'}"
+ path="${path//'\n'/$'\n'}"
+ fi
paths+=("$path")
- done < <( sed --binary -- 's/^\\\?[[:alnum:]]\+ [ *]//' "$sums_path" )
-
- [ "${#paths[@]}" -eq 0 ] && return 0
+ done < "$sums_path"
- printf -- "$fmt" ${paths[@]+"${paths[@]}"}
+ [ "${#paths[@]}" -gt 0 ] && printf -- "$fmt" ${paths[@]+"${paths[@]}"}
)
sums_update() (