blob: 6f29ddfdc8747f77f3028937183aa37ab0220e81 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# Where shells disagree, the choices zash makes (see DESIGN.md).
# return takes its status modulo 256, as in bash and ksh.
r() { return 300; }; r; echo "return 300: $?"
# ^ negates a bracket expression, like !, as in bash and ksh.
touch a1 b1; echo [^a]1
# Failing regular builtins return 1 (dash returns 2 from some).
umask bad 2>/dev/null; echo "umask: $?"
cd /nonexistent 2>/dev/null; echo "cd: $?"
# The :? message says what was wrong.
(: "${empty:?}") 2>&1 | sed 's/^.*: empty/empty/'
(: "${unset?}") 2>&1 | sed 's/^.*: unset/unset/'
# A variable holding an expression is evaluated, as in ksh and bash.
r=x; x=7; echo "indirect: $((r))"
e='2 * 3'; echo "expression: $((e + 1))"
c1=c2; c2=c1; ( : $((c1)) ) 2>&1 | sed 's/^.*arithmetic/arithmetic/'
# An existing file is newer than a missing one (POSIX.1-2024, bash).
: >new; [ new -nt missing ] && echo "-nt missing: true"
[ missing -ot new ] && echo "-ot missing: true"
# printf %c with an empty argument writes a NUL, as dash and bash do.
printf '%c|%c' '' | od -An -c | tr -s ' '
|