April Chin wrote: [snip] > > Ok... > > ... right now ksh93 prints the following output for the following two > > testcases: > > -- snip -- > > $ ksh93 -c 'unset kjashdjkashd ; print $? ; unset kjashdjkashd ; print > > $?' > > 1 > > 1 > > $ ksh93 -c 'kjashdjkashd="abc" ; unset kjashdjkashd ; print $? ; unset > > kjashdjkashd ; print $?' > > 0 > > 0 > > -- snip -- > > > > What is the expected output in both cases ? Does this change mean the > > shell will have to track variable names even if they were "unset" (until > > now I always interpreted $ unset varname # as a variable/shell > > equivalent to "rm", e.g. once the variable is "unset" it is really gone > > and no traces are left) or that "unset" just returns "0" in all cases > > above ? > > In both cases, unset should return 0. If it doesn't do it now, I don't > think that any tracking is needed for unset variables.
Attached (as "ksh93_integration_unset_no_such_var_fix001.diff.txt") is a prototype patch which fixes the problem (well, most of it, right now $ unset '1' # or $ unset '$' # do not return an error) and adds a new option ("-e") to get the old behaviour for backwards-compatibilty. ---- Bye, Roland -- __ . . __ (o.\ \/ /.o) roland.mainz at nrubsig.org \__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer /O /==\ O\ TEL +49 641 3992797 (;O/ \/ \O;) -------------- next part -------------- Index: src/lib/libshell/common/bltins/typeset.c =================================================================== --- src/lib/libshell/common/bltins/typeset.c (revision 1371) +++ src/lib/libshell/common/bltins/typeset.c (working copy) @@ -922,7 +922,7 @@ register const char *name; register int r; Dt_t *dp; - int nflag=0,all=0,isfun; + int eflag=0,nflag=0,all=0,isfun; NOT_USED(argc); if(troot==shp->alias_tree) { @@ -940,6 +940,9 @@ case 'a': all=1; break; + case 'e': + eflag=1; + break; case 'n': nflag = NV_NOREF; case 'v': @@ -978,7 +981,8 @@ { if(nv_isarray(np) && name[strlen(name)-1]==']' && !nv_getsub(np)) { - r=1; + if (eflag) + r=1; continue; } @@ -993,7 +997,8 @@ nv_delete(np,troot,NV_NOFREE); } else - r = 1; + if (eflag) + r = 1; } return(r); } Index: src/lib/libshell/common/tests/sun_solaris_vartree002.sh =================================================================== --- src/lib/libshell/common/tests/sun_solaris_vartree002.sh (revision 1371) +++ src/lib/libshell/common/tests/sun_solaris_vartree002.sh (working copy) @@ -144,12 +144,12 @@ [[ "$c" == "" ]] && c='-' #if [[ "${dest_tree.l1["$a"]}" == "" ]] ; then - if ! (unset dest_tree.l1["$a"]) ; then + if ! (unset -e dest_tree.l1["$a"]) ; then typeset -A dest_tree.l1["$a"].l2 fi #if [[ "${dest_tree.l1["$a"].l2["$b"]}" == "" ]] ; then - if ! (unset dest_tree.l1["$a"].l2["$b"]) ; then + if ! (unset -e dest_tree.l1["$a"].l2["$b"]) ; then typeset -A dest_tree.l1["$a"].l2["$b"].l3 fi @@ -301,43 +301,43 @@ #### test "unset" in a subshell - ( unset 'mytree_global1.l1[urw].l2[itc zapfdingbats]' ) || \ + ( unset -e 'mytree_global1.l1[urw].l2[itc zapfdingbats]' ) || \ err_exit "Try 1: Variable 'mytree_global1.l1[urw].l2[itc zapfdingbats]' not found." - ( unset 'mytree_global1.l1[urw].l2[itc zapfdingbats]' ) || \ + ( unset -e 'mytree_global1.l1[urw].l2[itc zapfdingbats]' ) || \ err_exit "Try 2: Variable 'mytree_global1.l1[urw].l2[itc zapfdingbats]' not found." # remove parent node (array element) and then check whether the child is gone, too: ( set -o errexit - unset 'mytree_global1.l1[urw].l2[itc zapfdingbats]' - ! unset 'mytree_global1.l1[urw].l2[itc zapfdingbats].l3[medium].entries[abcd].filenames[0]' + unset -e 'mytree_global1.l1[urw].l2[itc zapfdingbats]' + ! unset -e 'mytree_global1.l1[urw].l2[itc zapfdingbats].l3[medium].entries[abcd].filenames[0]' ) || err_exit "Global: Parent node removed (array element), child still exists" ( set -o errexit - unset 'mytree_local1.l1[urw].l2[itc zapfdingbats]' - ! unset 'mytree_local1.l1[urw].l2[itc zapfdingbats].l3[medium].entries[abcd].filenames[0]' + unset -e 'mytree_local1.l1[urw].l2[itc zapfdingbats]' + ! unset -e 'mytree_local1.l1[urw].l2[itc zapfdingbats].l3[medium].entries[abcd].filenames[0]' ) || err_exit "Local: Parent node removed (array element), child still exists" # remove parent node (array variable) and then check whether the child is gone, too: ( set -o errexit - unset 'mytree_local1.l1[urw].l2' - ! unset 'mytree_local1.l1[urw].l2[itc zapfdingbats].l3[medium].entries[abcd].filenames[0]' + unset -e 'mytree_local1.l1[urw].l2' + ! unset -e 'mytree_local1.l1[urw].l2[itc zapfdingbats].l3[medium].entries[abcd].filenames[0]' ) || err_exit "Global: Parent node removed (array variable), child still exists" ( set -o errexit - unset 'mytree_local1.l1[urw].l2' - ! unset 'mytree_local1.l1[urw].l2[itc zapfdingbats].l3[medium].entries[abcd].filenames[0]' + unset -e 'mytree_local1.l1[urw].l2' + ! unset -e 'mytree_local1.l1[urw].l2[itc zapfdingbats].l3[medium].entries[abcd].filenames[0]' ) || err_exit "Local: Parent node removed (array variable), child still exists" #### test "unset" and compare trees - unset 'mytree_global1.l1[urw].l2[itc zapfdingbats].l3[medium].entries[abcd].filenames[0]' || + unset -e 'mytree_global1.l1[urw].l2[itc zapfdingbats].l3[medium].entries[abcd].filenames[0]' || err_exit "Variable 'mytree_global1.l1[urw].l2[itc zapfdingbats].l3[medium].entries[abcd].filenames[0]' not found." [[ "${mytree_global1}" != "${mytree_local1}" ]] || err_exit "mytree_global1 and mytree_local1 should differ" - unset 'mytree_local1.l1[urw].l2[itc zapfdingbats].l3[medium].entries[abcd].filenames[0]' || + unset -e 'mytree_local1.l1[urw].l2[itc zapfdingbats].l3[medium].entries[abcd].filenames[0]' || err_exit "Variable 'mytree_local1.l1[urw].l2[itc zapfdingbats].l3[medium].entries[abcd].filenames[0]' not found." # Compare trees (after "unset") Index: src/lib/libshell/common/data/builtins.c =================================================================== --- src/lib/libshell/common/data/builtins.c (revision 1371) +++ src/lib/libshell/common/data/builtins.c (working copy) @@ -1731,7 +1731,7 @@ ; const char sh_optuniverse[] = " [name]"; const char sh_optunset[] = -"[-1c?\n@(#)$Id: unset (AT&T Research) 1999-07-07 $\n]" +"[-1c?\n@(#)$Id: unset (AT&T Research) 2009-01-12 $\n]" USAGE_LICENSE "[+NAME?unset - unset values and attributes of variables and functions]" "[+DESCRIPTION?For each \aname\a specified, \bunset\b unsets the variable, " @@ -1740,6 +1740,7 @@ "[n?If \aname\a refers to variable that is a reference, the variable \aname\a " "will be unset rather than the variable it references. Otherwise, " "is is equivalent to \b-v\b.]" +"[e?Return a non-zero exit code if one or more operands were not defined.]" "[f?\aname\a refers to a function name and the shell will unset the " "function definition.]" "[v?\aname\a refers to a variable name and the shell will unset it and "