summaryrefslogtreecommitdiffhomepage
path: root/tests/posix/expand-edge.sh
blob: f1027702fb3a7a986863fcb061f568e608ba58f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# shellcheck shell=sh
# shellcheck disable=SC1037,SC2005,SC2006,SC2016,SC2028,SC2034,SC2046,SC2068,SC2086,SC2116,SC2145,SC3058
# ^ the point of this file: expansions written the wrong way on purpose.
# Expansion corner cases.
set -- "a b" "" c
printf '<%s>' "$@"; echo
printf '<%s>' $@; echo
printf '<%s>' "$*"; echo
printf '<%s>' "x$@y"; echo
printf '<%s>' "${@}"; echo
printf '<%s>' ${1+"$@"}; echo
set --
printf '<%s>' "$@"; echo "[none]"
printf '<%s>' "x$@"; echo
printf '<%s>' "$*"; echo
IFS=:; set -- a b c; echo "$*"; x="$*"; echo "$x"; unset IFS
IFS=; set -- a b; echo "$*"; unset IFS
v="  lead  trail  "; printf '<%s>' $v; echo
IFS=,; v="a,,b,"; printf '<%s>' $v; echo; unset IFS
IFS=' ,'; v=" a , b ,, c "; printf '<%s>' $v; echo; unset IFS
v='*'; printf '<%s>' $v "$v"; echo
unset u; echo "${u-def}" "${u:-def}" "${u+alt}" "[${u:+alt}]"
e=; echo "[${e-def}]" "${e:-def}" "${e+alt}" "[${e:+alt}]"
echo "${u:=assigned}" "$u"
(echo "${nope?custom message}") 2>&1 | sed 's/^.*nope/nope/'
(echo "${nope:?}") 2>/dev/null; echo "status=$?"
x=abcabc; echo "${x#*b}" "${x##*b}" "${x%b*}" "${x%%b*}" "${#x}"
x='a*b'; echo "${x#a\*}" "${x#"a*"}" "${x%'*b'}"
x=/usr/local/bin/sh; echo "${x##*/}" "${x%/*}"
# "${#@}" counts parameters in ksh and bash but is the length of "$*" in
# dash, so it is zash/param-len-at.sh's business, not this file's.
echo "${#}"
echo ${x:+"quoted alt"} | wc -w | tr -d ' '
a=1; b='$a'; echo "$b" ${b}
echo "$(echo "nested $(echo "deeper")")"
echo `echo \`echo inner\``
echo "a\$b" 'a\$b' a\$b
echo "\a\b\\c\"d"
echo ~nosuchuser123 ~/x | sed "s|$HOME|HOME|"
x=~; echo "$x" | sed "s|$HOME|HOME|"
y=a:~:b; echo "$y" | sed "s|$HOME|HOME|g"
echo $((1+2))$((3)) "$((4*5))"
echo ${x+$(echo sub)}
echo "${u-$(echo default)}"
unset u; echo "${u-"a b"}" | wc -w | tr -d ' '
f() { echo "$#"; }; f "$@"; f $u; f "$u"; f ''
set -- 1 2 3 4 5 6 7 8 9 10 11; echo "$10" "${10}" "${11}"