summaryrefslogtreecommitdiffstats
path: root/runtime/syntax/testdir/input/sh_03.sh
blob: 8dd6dab9c379b4a89d888cd8282c36aed4831d13 (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
#!/bin/ksh
#  Test variable modifiers
# Variable=value
Variable='value'
Variable="value"
VariableA="pat1xxpat2"
VariableB="pat2xxpat1"
echo ${#}
echo ${#VariableA}
echo ${VariableA#pat1}
echo ${VariableA##pat1}
echo ${VariableB%pat1}
echo ${VariableB%%pat1}

# This gets marked as an error
Variable=${VariableB:+${VariableC:=eng}}	# :+ seems to work for ksh as well as bash
Variable=${VariableB:-${VariableC:-eng}}	# :- is ksh and bash

# This is OK
Variable='${VariableB:+${VariableC:=eng}}'
Variable='${VariableB:-${VariableC:-eng}}'
Variable="${VariableB:+${VariableC:=eng}}"	# :+ seems to work for ksh as well as bash
Variable="${VariableB:-${VariableC:-eng}}"  # :- is ksh and bash

# These are OK
: ${VariableB:-${VariableC:-eng}}
: "${VariableB:-${VariableC:-eng}}"
: '${VariableB:-${VariableC:-eng}}'

# Another test
Variable=${VariableB:-${VariableC:-${VariableD:-${VariableE:=eng}}}}
       :        ${VariableB:=${VariableC:-${VariableD:-${VariableE:=eng}}}}