Article View: comp.unix.shell
Article #1775bourne sh, problems with var setting in case/esac
From: bothe
Date: Wed, 14 Nov 1990 19:43
Date: Wed, 14 Nov 1990 19:43
42 lines
1611 bytes
1611 bytes
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@nixdorf.com
(SNI) !USA: bothe.muc@nixdorf.de, NERV: bothe.muc
Technical Details
Message-ID:
<1236@netmuc.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!think.com!linus!nixbur!nixpbe!netmuc!net7!botheShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!think.com!linus!nixbur!nixpbe!netmuc!net7!bothe From: bothe@net7.uucp Newsgroups: comp.unix.shell Subject: bourne sh, problems with var setting in case/esac Keywords: sh, case Message-ID: <1236@netmuc.UUCP> Date: 14 Nov 90 19:43:40 GMT Sender: bnews@netmuc.UUCP Distribution: comp Lines: 42