delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/10/25/11:40:04

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
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
Date: Mon, 25 Oct 2004 11:38:15 -0400 (EDT)
From: Igor Pechtchanski <pechtcha AT cs DOT nyu DOT edu>
Reply-To: cygwin AT cygwin DOT com
To: Axel Dreher <axeldreher AT gmx DOT de>
cc: cygwin AT cygwin DOT com
Subject: Re: Issues with read and loop in bash
In-Reply-To: <loom.20041025T112809-629@post.gmane.org>
Message-ID: <Pine.GSO.4.61.0410251135080.16595@slinky.cs.nyu.edu>
References: <loom DOT 20041025T112809-629 AT post DOT gmane DOT org>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.39

On Mon, 25 Oct 2004, Axel Dreher wrote:

> Hello @all,
>
> I`m new to this group, so please apologize if my posting does not
> conform to formal restrictions. ;-)
>
> In addition, my english is quite poor, so please apologize this too. ;-)
>
> Well, I have following problem. I searched this already in the
> gmane-database for this newsgroup, but didn`t find an appropriate
> answer. (possible bad searchwords?)
>
> I wrote a shell script using bash at Suse 9.1.
> This shell script includes following section:
> ----------------snip-------------------------------
> while read lines
>
>    do
>        check=FALSE
>        while read lines_2
>
>            do
> 	        if ([ $lines = $lines_2 ]) then    # this is line 63
>
> 		check=TRUE
> 		break
>
> 		fi
>
>            done < $3/only_hashes_right.log
>
>      if ([ $check = FALSE ]) then
>
>         echo $lines >> $3/singles_only_hashes.log
>
>      fi
>
>    done < $3/only_hashes_left.log
> -----------------------snip------------------------------------
>
> The logfiles just have hashes (of pdf-files) inside, created by md5sum.
> Each of the 2 logfiles have some thousand of these hashes, one per line.
> In the outer loop each hash is read from the first logfile and will be
> compared with each hash in the second logfile using the inner loop. If a
> "Partner" is found, the inner loop breaks. If no Partner is found, this
> hash is printed in a third logfile called singles_only_hashes.log, as
> you can see above. I`m not sure if the check-variable is necessary,
> though. With Suse this section and the whole script works properly, but
> not with bash under cygwin with Windows XP. It creates following error
> message:
>
> line 63: [: too many arguments
>
> and this a thousand of times. I marked the corresponding line in the
> script above. I also used as "shebang" this: #!/bin/bash instead of
> #!/bin/sh, but this didn`t solve the problem.
>
> Could anybody point me to the right direction?

Just for the record (yes, I know you've fixed the problem), line 63 above
contains unquoted strings, which will cause problems if the file has
spaces.  For that matter, so does most of the rest of the chunk above.
You should almost always quote the variable references.
HTH,
	Igor
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha AT cs DOT nyu DOT edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor AT watson DOT ibm DOT com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski, Ph.D.
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"Happiness lies in being privileged to work hard for long hours in doing
whatever you think is worth doing."  -- Dr. Jubal Harshaw

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