bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Add support for array .pop()


From: lolilolicon
Subject: Re: Add support for array .pop()
Date: Sun, 16 Oct 2016 00:16:04 +0800

On Sat, Oct 15, 2016 at 10:50 PM, konsolebox <address@hidden> wrote:
>
> My version would be this:
>
> function array_pop { declare -n __a=$1 __v=$2; __v=${__a[-1]}; unset
> '__a[-1]'; }
>

Here's another version which avoids local or nameref variables,

pop() {
    [[ -v $1 ]] || return
    set -- "$1[-1]" "$2"
    eval set -- \"address@hidden" \"\$\{"$1"\}\"
    printf -v "$2" '%s' "$3"
    unset "$1"
}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]