strange shell behavior...thoughts?
Gordon Messmer
yinyang at eburg.com
Mon Sep 15 08:28:41 UTC 2008
Kevin Martin wrote:
> So I'm fairly confused at this point.
> Start with a /bin/sh shell.
> Then do:
>
> sh-3.2$ unset $?
> sh: unset: `0': not a valid identifier
You mean "unset ?". That's not to say that it'll work, but when you
unset variables, you don't precede them with the $ character.
> ok, no problem; then do
>
> sh-3.2$ /bin/ksh -c " set -xv ; grep ABCD b ; echo $? ; if [ "$?" =
> "0" ] ; then echo yes ; fi"
> + grep ABCD b
> ABCD="C" ; export ABCD
> + echo 1
> 1
> + [ 1 = 0 ]
>
> WHAT?
If you want to understand what's going on, try:
$ false
$ echo "set -xv ; grep ABCD b ; echo $? ; if [ "$?" ="0" ] ; then echo
yes ; fi"
If you want to pass "$" characters like that, you'll need to escape them
or use single quotes:
$ ksh -c " set -xv ; grep ABCD b ; echo \$? ; if [ \"\$?\" =\"0\" ] ;
then echo yes ; fi"
$ ksh -c ' set -xv ; grep ABCD b ; echo $? ; if [ "$?" ="0" ] ; then
echo yes ; fi'
More information about the fedora-list
mailing list