mirror of
https://github.com/Pmodules/Pmodules.git
synced 2026-07-11 16:00:48 +02:00
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:
+18
-3
@@ -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__[@]}
|
||||
|
||||
Reference in New Issue
Block a user