Problem when using variable assignment, backticks in shell script

Jim Easton jim@cs.ualberta.ca
Fri Sep 1 02:16:00 GMT 2006


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/



More information about the Cygwin mailing list