bourne sh, problems with var setting in case/esac

bothe at net7.uucp bothe at net7.uucp
Thu Nov 15 06:43:40 AEST 1990


in sh, case does not save vars correct (i think)

such a script shtest:
#==== start script shtest =====
echo "1=$1, 2=$2, #=$#"
case $1 in
-d)
	shift
	echo "1=$1, 2=$2, #=$#"
	b="$1 x"
	echo ++++++++++++++++ $b
esac |
cat
echo ++++++++++++++++ $b
echo "1=$1, 2=$2, #=$#"
#==== end script shtest =====

called with:
shtest -d affe

results:                       |    remarks:
_________________________      |    _____________________
1=-d, 2=affe, #=2              |    orig params, ok
1=affe, 2=, #=1                |    ok, params shifted
++++++++++++++++ affe x        |    ok
++++++++++++++++               |    oops, where is content of b ?
1=-d, 2=affe, #=2              |    hey, hu, what is going on with shift ?

i did expect only 1 parameter ($1=affe) after esac, and var b set as
in case !

is it a bug or a feature

if i don't pipe esac and not use cat, all is ok, but i want to pipe !


what to do ?
S I E M E N S   Richard Bothe, NIXDORF COMPUTER AG, Dep PDT-M 24
-------------   Berliner Str. 95, W-8000 Munic (West Germany)
N I X D O R F   Tel.: +49 89 3601 2956, USA: bothe.muc at nixdorf.com
    (SNI)       !USA: bothe.muc at nixdorf.de, NERV: bothe.muc



More information about the Comp.unix.shell mailing list