From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16247 invoked from network); 14 Feb 2001 23:05:27 -0000 Received: from sunsite.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 14 Feb 2001 23:05:27 -0000 Received: (qmail 2346 invoked by alias); 14 Feb 2001 23:05:15 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 3620 Received: (qmail 2332 invoked from network); 14 Feb 2001 23:05:14 -0000 Date: Wed, 14 Feb 2001 23:11:03 +0100 From: Thomas =?iso-8859-1?Q?K=F6hler?= To: zsh-users@sunsite.auc.dk Subject: Re: Problems with Parameter Expansion := Message-ID: <20010214231103.C2201@picard.franken.de> Mail-Followup-To: Thomas =?iso-8859-1?Q?K=F6hler?= , zsh-users@sunsite.auc.dk References: Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="/Uq4LBwYP4y1W6pO" Content-Disposition: inline User-Agent: Mutt/1.3.12i In-Reply-To: ; from goetzger@gmx.net on Wed, Feb 14, 2001 at 09:28:04PM +0100 X-Operating-System: Linux picard 2.2.17 X-Editor: VIM - Vi IMproved 6.0v ALPHA http://www.vim.org/ X-IRC: tirc; Nick: jeanluc X-URL: http://jeanluc-picard.de/ --/Uq4LBwYP4y1W6pO Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Feb 14, 2001 at 09:28:04PM +0100, Heinrich G=F6tzger wrote: >=20 > Hi there again, >=20 > my second problem is that I want to set NAME to WORD, > if NAME is not set, example from zsh.info: > ${NAME:=3DWORD} Fine :-) > my script (called script.sh): > -- begin -- > if [ ${NAME:=3D`hostname | cut -c5-8`} ] > then > echo $NAME > fi >=20 > if [ ${NAME1:=3D""} =3D "true" ] > then > echo "true" > fi > -- end -- > asuming, my hosts name is exploding: >=20 > $ echo $NAME > zsh: NAME: parameter not set > $ echo $NAME1 > zsh: NAME1: parameter not set > $ . script.sh > odin > script.sh:6: parse error: condition expected: =3D Of course :-) > Again, it runs with bash and ksh. >=20 > Why does it not expand NAME1 to "" ? It expands NAME1 to an empty string, which I would expect. Why? Let's see: if [ ${NAME1:=3D""} =3D "true" ] ; then echo "true" ; fi ^^^^^^^^^^^^ Put value of $NAME1 here. Use empty default. Oops, the shell sees this: if [ =3D "true" ] ; then echo "true" ; fi > running it with set -x it shows: > $ . script.sh > +-zsh:8> . script.sh > +script.sh:1> [ odin ] > +script.sh:3> echo odin > odin > +script.sh:6> [ =3D true ] > script.sh:6: parse error: condition expected: =3D >=20 > Any ideas? Of course :-) Either use [[ ]] like this: if [[ ${NAME1:=3D""} =3D "true" ]] ; then echo "true" ; fi Or, if your shell is also supposed to run with bash/ksh, use something like this: if [ "${NAME1:=3D''}" =3D "true" ] ; then echo "true" ; fi > Thanks for our help. >=20 > Regards >=20 > Heinrich Ciao, Thomas --=20 Thomas K=F6hler Email: jean-luc@picard.franken.de | LCARS - Linux <>< WWW: http://jeanluc-picard.de | for Computers IRC: jeanluc | on All Real PGP public key available from Homepage! | Starships --/Uq4LBwYP4y1W6pO Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.4 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE6iwJ3TEYXWMJlHuYRAtlIAJ979yv73NeyZ9X7QS1/y9RjZlzZYwCfdoVL 3IiR2gBHg3tmaaT9UIpHAUg= =u4ug -----END PGP SIGNATURE----- --/Uq4LBwYP4y1W6pO--