bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: The usage of [[ (not with if)


From: Davide Brini
Subject: Re: The usage of [[ (not with if)
Date: Wed, 4 Aug 2010 16:08:05 +0100
User-agent: KMail/1.13.3 (Linux/2.6.32-gentoo-r10; KDE/4.4.4; x86_64; ; )

On Wednesday 04 Aug 2010 16:03:25 Peng Yu wrote:
 
> I have the following script and output. The man page says "Return  a
> status  of  0 or 1 depending on the evaluation of the conditional
> expression expression." Therefore, I thought that the two printf
> statements should print 1 and 0 respectively. But both of them print
> 0. I'm wondering what [[ should return if it is not used with a if
> statement.
> 
> $ cat main.sh
> #!/usr/bin/env bash
> 
> printf '%d\n' `[[ 10 -gt 1 ]]`
> printf '%d\n' `[[ 1 -gt 10 ]]`
> if [[ 10 -gt 1 ]]
> then
>   echo xxx
> fi
> $ ./main.sh
> 0
> 0
> xxx

You're confusing "return value of the command" with "output of the command".

-- 
D.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]