delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/08/29/12:12:23

X-Spam-Check-By: sourceware.org
From: "Dave Korn" <dave DOT korn AT artimi DOT com>
To: <cygwin AT cygwin DOT com>
Subject: RE: Problem when using variable assignment, backticks in shell script
Date: Tue, 29 Aug 2006 17:11:56 +0100
Message-ID: <035501c6cb85$d9578bc0$a501a8c0@CAM.ARTIMI.COM>
MIME-Version: 1.0
X-Mailer: Microsoft Office Outlook 11
In-Reply-To: <017630AA6DF2DF4EBC1DD4454F8EE29708D754BA@rsana-ex-hq1.NA.RSA.NET>
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On 29 August 2006 17:04, Silva, Russell wrote:


> The value of $? is always 0 when this problem occurs, even if it should
> be a non-zero value.  For instance:
> 
> <bug_reproduce3.sh>
> #!/bin/bash
> # make 1000 attempts to reproduce the bug
> for i in `seq 1 1000`
> do
>   # ls should return incorrect usage = error code 2
>   x=$(ls -j 2>&1);
>   # if the bug has occurred
>   if [[ $x == "" ]]
>   then
>     # this outputs 0, but "incorrect usage" ls should (and does) return
> 2
>     echo $?
>   fi
> done

> When the bug occurs, causing $x to be empty, the value of $? is 0 when
> it should be 2.


  Are you sure you aren't testing the return value of the 'if' or perhaps the
'[[' command there?  What happens if you rewrite it as:

#!/bin/bash
# make 1000 attempts to reproduce the bug
for i in `seq 1 1000`
do
  # ls should return incorrect usage = error code 2
  x=$(ls -j 2>&1); y=$?
  # if the bug has occurred
  if [[ $x == "" ]]
  then
    echo $y
  fi
done


    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019