1#
2# CDDL HEADER START
3#
4# The contents of this file are subject to the terms of the
5# Common Development and Distribution License (the "License").
6# You may not use this file except in compliance with the License.
7#
8# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9# or http://www.opensolaris.org/os/licensing.
10# See the License for the specific language governing permissions
11# and limitations under the License.
12#
13# When distributing Covered Code, include this CDDL HEADER in each
14# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15# If applicable, add the following below this CDDL HEADER, with the
16# fields enclosed by brackets "[]" replaced with your own identifying
17# information: Portions Copyright [yyyy] [name of copyright owner]
18#
19# CDDL HEADER END
20#
21
22#
23# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
24#
25
26#
27# Test whether CR #6754020 ("ksh93 does weird '[' expansion") has
28# been fixed.
29#
30# Quote from CR #6754020:
31# ---- snip ----
32# The problem is that subprocess uses /bin/sh as the shell when it
33# spins off the process. As Brad demonstrated:
34# /bin/sh -c 'echo F[[O]'
35# F[[O][
36#
37# In short, this bug only appears when run through the test suite,
38# or by people  running /bin/sh who don't understand how their shell
39# treats special characters.
40# -- snip --
41#
42# In this case ksh93 has a bug which causes "F[[O]" to be expanded
43# in a wrong way.
44# ---- snip ----
45
46
47# test setup
48function err_exit
49{
50	print -u2 -n "\t"
51	print -u2 -r ${Command}[$1]: "${@:2}"
52	(( Errors < 127 && Errors++ ))
53}
54alias err_exit='err_exit $LINENO'
55
56set -o nounset
57Command=${0##*/}
58integer Errors=0
59
60
61typeset s
62
63# test using "echo"
64s="$(${SHELL} -c 'echo F[[O]')"
65[[ "$s" == 'F[[O]' ]] || err_exit "Expected 'F[[O]', got $s"
66
67s="$(${SHELL} -c 'echo F[[[O]]')"
68[[ "$s" == 'F[[[O]]' ]] || err_exit "Expected 'F[[[O]]', got $s"
69
70
71# test using "print"
72s="$(${SHELL} -c 'print F[[O]')"
73[[ "$s" == 'F[[O]' ]] || err_exit "Expected 'F[[O]', got $s"
74
75s="$(${SHELL} -c 'print F[[[O]]')"
76[[ "$s" == 'F[[[O]]' ]] || err_exit "Expected 'F[[[O]]', got $s"
77
78
79# tests done
80exit $((Errors))
81