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: cygwin bash script suddenly can't find ls, grep


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]