Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[spec/var-op-test] Extend tests for ${@:-}
Browse files Browse the repository at this point in the history
akinomyoga committed Jan 3, 2025
1 parent 77e2aea commit 655d14d
Showing 1 changed file with 71 additions and 1 deletion.
72 changes: 71 additions & 1 deletion spec/var-op-test.test.sh
Original file line number Diff line number Diff line change
@@ -381,7 +381,7 @@ a3=plus
## N-I zsh stdout-json: "empty=\na1=\n"
## N-I zsh status: 1

#### $@ and - and +
#### $@ (empty) and - and +
echo argv=${@-minus}
echo argv=${@+plus}
echo argv=${@:-minus}
@@ -399,6 +399,76 @@ argv=minus
argv=
## END

#### $@ ("") and - and +
set -- ""
echo argv=${@-minus}
echo argv=${@+plus}
echo argv=${@:-minus}
echo argv=${@:+plus}
## STDOUT:
argv=
argv=plus
argv=minus
argv=
## END

# Zsh treats $@ as an array unlike Bash converting it to a string by joining it
# with a space.

## OK zsh STDOUT:
argv=
argv=plus
argv=
argv=plus
## END

#### $@ ("" "") and - and +
set -- "" ""
echo argv=${@-minus}
echo argv=${@+plus}
echo argv=${@:-minus}
echo argv=${@:+plus}
## STDOUT:
argv=
argv=plus
argv=
argv=plus
## END

#### $* ("" "") and - and + (IFS=)
set -- "" ""
IFS=
echo argv=${*-minus}
echo argv=${*+plus}
echo argv=${*:-minus}
echo argv=${*:+plus}
## STDOUT:
argv=
argv=plus
argv=
argv=plus
## END
## BUG mksh/osh STDOUT:
argv=
argv=plus
argv=minus
argv=
## END

#### "$*" ("" "") and - and + (IFS=)
set -- "" ""
IFS=
echo "argv=${*-minus}"
echo "argv=${*+plus}"
echo "argv=${*:-minus}"
echo "argv=${*:+plus}"
## STDOUT:
argv=
argv=plus
argv=minus
argv=
## END

#### assoc array and - and +
case $SH in (dash|mksh) exit ;; esac

0 comments on commit 655d14d

Please sign in to comment.