delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2014/10/14/16:53:35

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:message-id:date:from:mime-version:to:subject
:references:in-reply-to:content-type:content-transfer-encoding;
q=dns; s=default; b=jMtGLnznEzN6PQttrn1Opy0t9hx/Chp0wxejLtl7liA
IbIIe/lAwjnUxHQr+vzv3/AARLfrf04lKjSNcKVUb2gZDX/mgOzAtGNL/kFDbrz4
MIIBAWRPQ+kdSH1o7Rc0Tg3b+qZkSCc3ed3SyZmZymXNOXMcKIrVjKr3VZ9R5Lms
=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:message-id:date:from:mime-version:to:subject
:references:in-reply-to:content-type:content-transfer-encoding;
s=default; bh=mR+bsAbJiFQN1oTImOZ6UjFzsGg=; b=qYFGrLt6W57T8Rpa8
L2OFTiUDRNKJ3iCbLvEA9VYWRLitM+qWRIhAqrXHV0yFuxax6xRNVmiKQKeDjBvB
nPye2/Ngaig6IyEmj7aa8UcUoo+kjwLrT1jSTBO0ZvzovVLF7YJljBjdg9M8ECTD
XmEA/LTid+8qlshRs0wxpjT9vw=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
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
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2
X-HELO: smtp104.biz.mail.ne1.yahoo.com
X-Yahoo-SMTP: ycweUreswBCK.d0cygTP5tXwHncbOU7YVeVfIxOQoyRMI2IuIKLmUqE-
Message-ID: <543D8D3F.9090305@molconn.com>
Date: Tue, 14 Oct 2014 16:53:19 -0400
From: LMH <lmh_users-groups AT molconn DOT com>
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:29.0) Gecko/20100101 Firefox/29.0 SeaMonkey/2.26.1
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: cygwin bash script suddenly can't find ls, grep
References: <5439C59F DOT 5060308 AT molconn DOT com> <5439C8A6 DOT 5020605 AT cornell DOT edu> <5439CB8F DOT 9000708 AT molconn DOT com> <87fvetes6w DOT fsf AT Rainer DOT invalid>
In-Reply-To: <87fvetes6w.fsf@Rainer.invalid>
X-IsSubscribed: yes

Achim Gratz wrote:
> LMH writes:
>> Good Lord, I guess I wasn't thinking very clearly trying to use PATH as
>> a variable for something else. I changed to,
>>
>> FILE_DIR=$(ls -d './'$SET'/'$FOLD'/'$FOLD'_anneal/'$PARAM_SET'/'$AN_SET)
>> echo $FILE_DIR
>>
>> FILE_LIST=($(ls $FILE_DIR'/'*'out.txt' ))
>> echo ${FILE_LIST[@]}
>>
>> and everything is fine. I guess it was a bash issue after all. Thanks
>> for checking that out.
> 
> Are you trying to re-write some Windows BAT/CMD script perhaps?  It
> seems that you'd actually want to use find instead of ls and protect
> yourself a bit against the possibility of one of these path or file
> names containing whitespace.  The ls constructing FILE_LIST is probably
> not needed because the shell already globs the file names before ls ever
> gets to it.
> 
> 
> Regards,
> Achim.
> 

Thanks for the advice. I went to using something like,

FILE_LIST=($(ls
'./'$SET'/'$FOLD'/'$FOLD'_anneal/'$PARAM_SET'/'$AN_SET'/'*'out.txt' ))

instead of,

FILE_LIST='./'$SET'/'$FOLD'/'$FOLD'_anneal/'$PARAM_SET'/'$AN_SET'/'*'out.txt'

when I was creating a script because ls will throw an exception if there
is nothing found matching the glob. This is especially true when I am
using a long path with allot of variables. I often remove the ls once I
know the script is working. The the first syntax above also creates an
array.

FILE_DIR was assigned separately because it it used in some other places
in the script and convenient to have in scope.

I have also had problems evaluating strings that were created by
assigning with a glob.

If I had a file,
myfile_1.txt

and did,
file_name='myfile_'*'.txt'

and then,
if [ "$file_name" = "myfile_1.txt" ];

I have had issues getting the above conditional to evaluate as true.

If instead I do,
file_name=$(ls 'myfile_'*'.txt')

the conditional will evaluate properly.

Am I mistaken about this? I have not taken the time to run down all of
these issues when they occur, which I really should.

LMH

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019