2012-06-22 10:09:45 +08:00
|
|
|
# Test that subsequent cases do not blow away the status from previous ones
|
|
|
|
for val in one two three four
|
|
|
|
switch $val
|
|
|
|
case one
|
|
|
|
/bin/sh -c 'exit 1'
|
|
|
|
case two
|
|
|
|
/bin/sh -c 'exit 2'
|
|
|
|
case three
|
|
|
|
/bin/sh -c 'exit 3'
|
|
|
|
end
|
|
|
|
echo $status
|
|
|
|
end
|
|
|
|
|
|
|
|
echo
|
|
|
|
|
|
|
|
# Test that the `switch` builtin itself does not blow away status before evaluating a case
|
|
|
|
false
|
|
|
|
switch one
|
|
|
|
case one
|
|
|
|
echo $status
|
|
|
|
end
|
|
|
|
|
|
|
|
# Test that non-case tokens inside `switch` don't blow away status
|
|
|
|
# (why are these even allowed?)
|
|
|
|
false
|
|
|
|
switch one
|
|
|
|
true
|
|
|
|
case one
|
|
|
|
echo $status
|
|
|
|
end
|
2012-07-10 21:32:37 +08:00
|
|
|
|
|
|
|
#test contains -i
|
|
|
|
echo test contains -i
|
|
|
|
contains -i string a b c string d
|
|
|
|
contains -i string a b c d; or echo nothing
|
|
|
|
contains -i -- string a b c string d
|
|
|
|
contains -i -- -- a b c; or echo nothing
|
|
|
|
contains -i -- -- a b c -- v
|
2012-09-01 16:46:14 +08:00
|
|
|
|
2012-09-04 04:24:01 +08:00
|
|
|
# Test if, else, and else if
|
2012-09-01 16:46:14 +08:00
|
|
|
if true
|
|
|
|
echo alpha1.1
|
|
|
|
echo alpha1.2
|
2012-09-04 04:24:01 +08:00
|
|
|
else if false
|
2012-09-01 16:46:14 +08:00
|
|
|
echo beta1.1
|
|
|
|
echo beta1.2
|
2012-09-04 04:24:01 +08:00
|
|
|
else if false
|
2012-09-01 16:46:14 +08:00
|
|
|
echo gamma1.1
|
|
|
|
echo gamma1.2
|
|
|
|
else
|
|
|
|
echo delta1.1
|
|
|
|
echo delta1.2
|
|
|
|
end
|
|
|
|
|
|
|
|
if false
|
|
|
|
echo alpha2.1
|
|
|
|
echo alpha2.2
|
2012-09-04 04:24:01 +08:00
|
|
|
else if begin ; true ; end
|
2012-09-01 16:46:14 +08:00
|
|
|
echo beta2.1
|
|
|
|
echo beta2.2
|
2012-09-04 04:24:01 +08:00
|
|
|
else if begin ; echo nope2.1; false ; end
|
2012-09-01 16:46:14 +08:00
|
|
|
echo gamma2.1
|
|
|
|
echo gamma2.2
|
|
|
|
else
|
|
|
|
echo delta2.1
|
|
|
|
echo delta2.2
|
|
|
|
end
|
|
|
|
|
|
|
|
if false
|
|
|
|
echo alpha3.1
|
|
|
|
echo alpha3.2
|
2012-09-04 04:24:01 +08:00
|
|
|
else if begin ; echo yep3.1; false ; end
|
2012-09-01 16:46:14 +08:00
|
|
|
echo beta3.1
|
|
|
|
echo beta3.2
|
2012-09-04 04:24:01 +08:00
|
|
|
else if begin ; echo yep3.2; true ; end
|
2012-09-01 16:46:14 +08:00
|
|
|
echo gamma3.1
|
|
|
|
echo gamma3.2
|
|
|
|
else
|
|
|
|
echo delta3.1
|
|
|
|
echo delta3.2
|
|
|
|
end
|
|
|
|
|
|
|
|
if false
|
|
|
|
echo alpha4.1
|
|
|
|
echo alpha4.2
|
2012-09-04 04:24:01 +08:00
|
|
|
else if begin ; echo yep4.1; false ; end
|
2012-09-01 16:46:14 +08:00
|
|
|
echo beta4.1
|
|
|
|
echo beta4.2
|
2012-09-04 04:24:01 +08:00
|
|
|
else if begin ; echo yep4.2; false ; end
|
2012-09-01 16:46:14 +08:00
|
|
|
echo gamma4.1
|
|
|
|
echo gamma4.2
|
|
|
|
else
|
|
|
|
echo delta4.1
|
|
|
|
echo delta4.2
|
|
|
|
end
|