From 6cf25a57debb9ed65e45c358d9c5fad43fcb75e3 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Tue, 17 Jan 2023 11:19:49 -0700 Subject: hstow: readlink: don't collapse runs of blanks in filename or target --- bin/hstow | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'bin/hstow') diff --git a/bin/hstow b/bin/hstow index ff5ae181..21cbeca6 100755 --- a/bin/hstow +++ b/bin/hstow @@ -39,8 +39,13 @@ cchars="$(printf '*[\001-\037\177]*')" if ! command -v readlink >/dev/null; then readlink () { # Safe parse of ls(1) output given its POSIX specification. - ls -ld "$1" | tr -s ' ' \ - | cut -d' ' -f9- | cut -c$((4 + $(echo "$1" | wc -m)))- + # + # We want the ninth field onwards in awk's sense -- + # i.e. collapsing multiple runs of blanks between the first nine + # fields -- but we mustn't collapse blanks from there onwards. + ls -ld "$1" \ + | sed -E 's/^[[:blank:]]*([^[:blank:]]+[[:blank:]]+){8}.{'$(( + 3 + $(echo "$1" | wc -m)))'}//' } fi -- cgit v1.2.3