From: "Thomas Köhler" <jean-luc@picard.franken.de>
To: zsh-users@sunsite.auc.dk
Subject: Re: Problems with Parameter Expansion :=
Date: Wed, 14 Feb 2001 23:11:03 +0100 [thread overview]
Message-ID: <20010214231103.C2201@picard.franken.de> (raw)
In-Reply-To: <Pine.LNX.4.33.0102142100460.1246-100000@exploding.fh-konstanz.de>; from goetzger@gmx.net on Wed, Feb 14, 2001 at 09:28:04PM +0100
[-- Attachment #1: Type: text/plain, Size: 1904 bytes --]
On Wed, Feb 14, 2001 at 09:28:04PM +0100,
Heinrich Götzger <goetzger@gmx.net> wrote:
>
> Hi there again,
>
> my second problem is that I want to set NAME to WORD,
> if NAME is not set, example from zsh.info:
> ${NAME:=WORD}
Fine :-)
> my script (called script.sh):
> -- begin --
> if [ ${NAME:=`hostname | cut -c5-8`} ]
> then
> echo $NAME
> fi
>
> if [ ${NAME1:=""} = "true" ]
> then
> echo "true"
> fi
> -- end --
> asuming, my hosts name is exploding:
>
> $ echo $NAME
> zsh: NAME: parameter not set
> $ echo $NAME1
> zsh: NAME1: parameter not set
> $ . script.sh
> odin
> script.sh:6: parse error: condition expected: =
Of course :-)
> Again, it runs with bash and ksh.
>
> Why does it not expand NAME1 to "" ?
It expands NAME1 to an empty string, which I would expect. Why? Let's
see:
if [ ${NAME1:=""} = "true" ] ; then echo "true" ; fi
^^^^^^^^^^^^
Put value of $NAME1 here. Use empty default. Oops, the shell sees
this:
if [ = "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> [ = true ]
> script.sh:6: parse error: condition expected: =
>
> Any ideas?
Of course :-)
Either use [[ ]] like this:
if [[ ${NAME1:=""} = "true" ]] ; then echo "true" ; fi
Or, if your shell is also supposed to run with bash/ksh, use something
like this:
if [ "${NAME1:=''}" = "true" ] ; then echo "true" ; fi
> Thanks for our help.
>
> Regards
>
> Heinrich
Ciao,
Thomas
--
Thomas Köhler 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
[-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --]
prev parent reply other threads:[~2001-02-14 23:05 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-02-14 20:28 Heinrich Götzger
2001-02-14 20:56 ` Bart Schaefer
2001-02-14 22:11 ` Thomas Köhler [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20010214231103.C2201@picard.franken.de \
--to=jean-luc@picard.franken.de \
--cc=zsh-users@sunsite.auc.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).