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,

Mon, 28 Aug 2006 Russell Silva 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 what's it's worth I ran this script maybe a dozen times with no
hint of trouble.

HTH.
        Jim

#!/bin/bash

# create a file called "temp" with text contents "liars"
rm temp
touch temp
echo liars > temp

# make 1000 attempts to reproduce the bug
for i in `seq 1 1000`
do
  # use a backticked expression to assign the contents of "temp" 
  #   to variable $x
  x=`/usr/bin/cat < temp`;
  if [[ $x != "liars" ]]
  then
    # if this code is reached, the variable assignment failed somehow
    echo error attempt $i: \"$x\" is not the correct string \"liars\"
  fi
done

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