On Mon, Sep 08, 2003 at 03:48:37AM -0500, Branden Robinson wrote: > I do continue to think that: > > if [ -n "$var" ] > > is more readable than > > if [ "${var+set}" = "set" ]
both are not equivalent: the first one test if var is empty or unset the second one test if var is unset with bash: $ a="1" ; [ -n "$a" ] && echo "a is not empty" a is not empty $ a="" ; [ -n "$a" ] && echo "a is not empty" $ unset a ; [ -n "$a" ] && echo "a is not empty" and: $ unset a ; [ "${a+set}" = "set" ] && echo "a is set" $ a="" ; [ "${a+set}" = "set" ] && echo "a is set" a is set $ a="1" ; [ "${a+set}" = "set" ] && echo "a is set" a is set IMO, [ -n "$var" ] is equivalent to [ "${var:+set} = "set" ]. The first form seems to be more readable and less error prone :) PS: what is the simplest way to test if a variable is set? -- Nekral