Skip to content
Myr

[Fix] `nvm_supports_source_options`: work around a bug in bash 3.2

Before adoption: this commit came in with the history the project adopted, so no landing records it.

See https://github.com/creationix/nvm/issues/1978#issuecomment-453480231 Fixes #1978.

authored by Jordan Harband · committed by Jordan Harband · parent 1ede50c · Browse files · 2 files+31 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+31 added−1 removed

  • tests:+27 added−0 removed
  • other:+4 added−1 removed

2 files+31 added−1 removed

added:test/fast/Unit tests/nvm_supports_source_options+27 added
1#!/bin/sh23die () { echo "$@" ; exit 1; }45\. ../../../nvm.sh67x=08i=09runs=510calls=50011first_result=false12if (nvm_supports_source_options && printf .); then13 first_result=true14fi15while [ $x -le $runs ]; do16 y=$x17 x=$(( x + 1 ))18 while [ $i -le $calls ]; do19 this_result=false20 if (nvm_supports_source_options && printf .); then21 this_result=true22 fi23 [ $this_result = $first_result ] || die "call ${i}, run ${y} got ${this_result}; expected ${first_result}"24 i=$(( i + 1 ))25 done26done27echo "${runs} runs of ${calls} calls succeeded"
modified:nvm.sh+4 added-1 removed
3557 unmodified lines
3558}35593560nvm_supports_source_options() {3561 # shellcheck disable=SC1091,SC22403562 [ "_$(nvm_echo '[ $# -gt 0 ] && nvm_echo $1' | . /dev/stdin yes 2>/dev/null)" = "_yes" ]3562 [ "_$( . /dev/stdin yes 2> /dev/null <<'EOF'3563[ $# -gt 0 ] && nvm_echo $13564EOF3565 )" = "_yes" ]3566}35673568nvm_supports_xz() {3569 if [ -z "${1-}" ] || ! command which xz >/dev/null 2>&1; then
80 unmodified lines