|
Home > Archive > Unix Shell > May 2004 > Re: && in sh
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Villy Kruse 2004-05-31, 6:06 pm |
| On Thu, 27 May 2004 23:28:46 GMT,
seand <seand@internet.net> wrote:
> Hi all,
>
> What is the right format to make conditional check below work(bash/ksh)?
>
> if [ "$p1" -eq "$p2" && "$p3" -eq "$p4" ]; then
> ...
>
Equivalent (identical) to
if test "$p1" -eq "$p2" && "$p3" -eq "$p4" ; then
Looks like syntax error. The "test" command uses -a and -o as AND and
OR operands. If you want to use && you need
if test "$p1" -eq "$p2" && test "$p3" -eq "$p4" ; then
same as
if [ "$p1" -eq "$p2" ] && [ "$p3" -eq "$p4" ] ; then
> in bash, only [[ ]] seems ok.
>
Se the recent discussion of [[ ... ]] versus [ ... ]
Villy
| |
| Villy Kruse 2004-05-31, 6:06 pm |
| On Thu, 27 May 2004 19:08:06 -0700,
foo <foo@bar.baz> wrote:
> You can also separate the aggregate test statement
> into discrete tests, like this:
>
> if [ "$p1" == "$p2" ] && [ "$p3" == "$p4" ]; then
> ...
> fi
>
> Also note that for string comparisons we can use the == operator. Only when
> comparing integers do we need to use the -eq operator.
Me thinks it is "=" and not "==" is used in the "test" command. Otherwise
correct.
I alwayw thinks [ ... ] as syntactic suggar for the "test" command.
Villy
| |
| Michael Tosch 2004-05-31, 6:07 pm |
| In article <OQutc.191696$0qd.185465@twister01.bloor.is.net.cable.rogers.com>, "seand" <seand@internet.net> writes:
> Hi all,
>
> What is the right format to make conditional check below work(bash/ksh)?
>
> if [ "$p1" -eq "$p2" && "$p3" -eq "$p4" ]; then
> ....
>
> in bash, only [[ ]] seems ok.
>
>
> TIA
>
>
> -s
>
>
[ condition ]
is the same as
test condition
And according to
man test:
if [ "$p1" -eq "$p2" -a "$p3" -eq "$p4" ]; then
.....
--
Michael Tosch
IT Specialist
HP Managed Services Germany
Phone +49 2407 575 313
Mail: michael.tosch:hp.com
|
|
|
|
|