News for hackers. Stuff that matters.
Re:Pure Sh Bible by hddqsb on Tuesday May 02, 2023 @09:47AM (#35787338)
Your "zsh/bash" code doesn't actually use any zsh/bash-only features, so it is compatible with POSIX sh. But you have a quoting bug: you should escape the `$` in `$2` and `${3...}` to protect from double-eval.

I'd personally try to minimise the use of eval, e.g.

    prepend() {
        local val
        eval "val=\$$1"
        export "$1=$2${val:+${3-:}$val}"
    }

    append() {
        local val
        eval "val=\$$1"
        export "$1=${val:+$val${3-:}}$2"
    }
Re:Pure Sh Bible by hddqsb on Tuesday May 02, 2023 @12:33PM (#35790164)
(`local` is not in POSIX, I know)