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 Igor,

I don't know what you mean by the "error string", but the
backtick-output string is always empty.  stderr gives me nothing.  I've
tried the $(COMMAND) syntax as an alternative to the `COMMAND` syntax,
same problem.

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
</bug_reproduce3.sh>

When the bug occurs, causing $x to be empty, the value of $? is 0 when
it should be 2.  ls -j is incorrect usage of ls (i.e., the -j option
does not exist) and should return 2.  This can be verified easily:

$ ls -asdfghjkl
ls: invalid option -- j
Try `ls --help' for more information.

$ echo $?
2

Regards,

Russell Silva


-----Original Message-----
From: Igor Peshansky [mailto:pechtcha@cs.nyu.edu] 
Sent: Monday, August 28, 2006 5:25 PM
To: Silva, Russell
Cc: cygwin@cygwin.com
Subject: Re: Problem when using variable assignment, backticks in shell
script

On Mon, 28 Aug 2006, Silva, Russell wrote:

> I am having a problem using Cygwin, variable assignment, and backticks
> when shell scripting.  Occasionally, variables assigned using a
> backticked expression are not properly assigned; they are left empty.
> The problem appears to be non-deterministic.
>
> For instance, take this script:
> [snip <bug_reproduce.sh>]
>
> A few times out of the 1000 possible, the error code is reached:
>
> $ ./bug_reproduce.sh
> error attempt 245: "" is not the correct string "liars"

Is the error string always empty?  That would indicate to me that bash
somehow failed to launch the child process...  FWIW, bash retains the
exit code of the launched program in $? after a backtick assignment --
try
printing that out and see if there is a correlation.  Also, check the
output on stderr -- perhaps there's an error message printed?
	Igor
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_	    pechtcha@cs.nyu.edu |
igor@watson.ibm.com
ZZZzz /,`.-'`'    -.  ;-;;,_		Igor Peshansky, Ph.D. (name
changed!)
     |,4-  ) )-,_. ,\ (  `'-'		old name: Igor Pechtchanski
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"Las! je suis sot... -Mais non, tu ne l'es pas, puisque tu t'en rends
compte."
"But no -- you are no fool; you call yourself a fool, there's proof
enough in
that!" -- Rostand, "Cyrano de Bergerac"

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