This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Problem when using variable assignment, backticks in shell script


Hi Dave,

I tried this; it's an excellent point but isn't the problem.  I
experimented using your script version and $? is indeed set to 0 when
the backtick output is empty.

I'd be happy to hear more suggestions.  I also need to try this on
another machine (my home box, perhaps) to see if it's reproducible on
other machines.  Have you tried any of these scripts to see if it's a
problem general to Cygwin users?

Regards,

Russell

________________________________________
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


--
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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]