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
This commit is contained in:
2021-10-28 18:32:49 +02:00
parent c22422aca9
commit b241031fc1
+18 -3
View File
@@ -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__[@]}