[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ternary operator
From: |
Chris F.A. Johnson |
Subject: |
Re: ternary operator |
Date: |
24 Jun 2002 04:30:01 GMT |
User-agent: |
slrn/0.9.7.3 (Linux) |
In article <20020623085407.GA15296@caliban.org>, Ian Macdonald wrote:
> Hi,
>
> The bash man page lists the ternary operator:
>
> expr?expr:expr
>
> However, I can't figure out how one is supposed to use it in bash.
Note that this is in the "ARITHMETIC EVALUATION" section of the man page.
> I would expect it to be analagous to the same operator in C:
>
> $ [ foo = 1 ] ? echo yes : echo no
> bash: [: missing `]'
>
> but this is clearly not what bash is expecting.
>
> What am I missing?
Use it where you would use arithmetic evaluation:
$ q=5
$ echo $(( q == 2 ? 3 : 4 ))
4
$ q=2
$ echo $(( q == 2 ? 3 : 4 ))
3
--
Chris F.A. Johnson bq933@torfree.net
=================================================================
c.f.a.johnson@rogers.com http://cfaj.freeshell.org
cfaj@freeshell.org http://members.rogers.com/c.f.a.johnson
- ternary operator, Ian Macdonald, 2002/06/23
- Re: ternary operator,
Chris F.A. Johnson <=