From b241031fc13aac99de07b5287e4c551070503818 Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Thu, 28 Oct 2021 18:32:49 +0200 Subject: [PATCH] fix std::split_fname() in libstd.bash - if path start with a leading slash, remove it, otherwise the first component of the splitted path is empty --- Pmodules/libstd.bash | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Pmodules/libstd.bash b/Pmodules/libstd.bash index fedd0c4..bcec362 100644 --- a/Pmodules/libstd.bash +++ b/Pmodules/libstd.bash @@ -135,11 +135,26 @@ std::replace_path () { # # split file name # +# Args: +# $1 upvar +# $2 fname (=${@: -1}) +# or +# $1 upvar +# $2 number of components +# $3 fname (=${@: -1}) +# std::split_fname() { - local -r savedIFS="${IFS}" + local "$1" + local -r fname="${@: -1}" + if [[ "${fname:0:1}" == '/' ]]; then + local -r tmp="${fname:1}" + else + local -r tmp="${fname}" + fi + IFS='/' - local std__split_fname_result__=( $(echo "${@: -1}") ) - IFS=${savedIFS} + local std__split_fname_result__=( ${tmp} ) + unset IFS eval $1=\(\"\${std__split_fname_result__[@]}\"\) if (( $# >= 3 )); then eval $2=${#std__split_fname_result__[@]}