From be603b6fc18aaa59a35f668bc5eccd18b1ce41a0 Mon Sep 17 00:00:00 2001 From: Steven Baltakatei Sandoval Date: Tue, 23 May 2023 01:39:57 +0000 Subject: [PATCH] fix(user/bkdatev):Make compatible with Bash 3.2.57 - Note: In Bash 5.1, a negative length argument in a parameter substitution (i.e. the `$len` in `${myVar:$start_idx:$len}`) causes the last characters of the $myVar string to be truncated which is convenient in various applications. However, a negative length in Bash 3.2.57 (a macOS machine I happen to have) throws an error; for compatibility, I've instead added an additional arithemetical operation to calculate the positive length that corresponds to a truncation by 2 of the total string length. --- user/bkdatev | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) mode change 100755 => 100644 user/bkdatev diff --git a/user/bkdatev b/user/bkdatev old mode 100755 new mode 100644 index f2f92ec..3cc96d9 --- a/user/bkdatev +++ b/user/bkdatev @@ -2,7 +2,7 @@ # Desc: Baltakatei's verbose date command # Usage: bkdatev [args] # Example: bkdatev --date="2001-09-11T09:02:59-04" -# Version: 0.3.0 +# Version: 0.3.1 # Ref/Attrib: [1] "ISO 8601". Wikipedia. https://en.wikipedia.org/wiki/ISO_8601 # [2] "Changing the Locale in Wine" https://stackoverflow.com/a/16428951 # [3] "Shanghai vs Beijing" https://bugs.launchpad.net/ubuntu/+source/libgweather/+bug/228554 @@ -83,7 +83,9 @@ get_tz_offset() { #last2="$(rev <<< $ntz)" && last2="${last2:0:2}" && last2="$(rev <<< "$last2")"; if [[ "$last2" == "00" ]]; then ## ntz_out is truncated by 2 characters - ntz_out="${ntz:0:-2}"; + len_ntz="${#ntz}"; + len_ntz_out="$(( len_ntz - 2 ))"; + ntz_out=""${ntz:0:$len_ntz_out}; else ## ntz_out is ntz with semicolon inserted after HH ntz_out="$(insertStr "$ntz" 3 ":" )"; -- 2.30.2