public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* cygwin bash script suddenly can't find ls, grep
@ 2014-10-12  0:05 LMH
  2014-10-12  0:17 ` Ken Brown
  0 siblings, 1 reply; 8+ messages in thread
From: LMH @ 2014-10-12  0:05 UTC (permalink / raw)
  To: cygwin

Hello,

I have been working on a bash script and suddenly I started getting an
error that ls could not be found,

./remove_rows.sh: line 27: ls: command not found

I can run ls from the command line just fine. There is also an ls
command before line 27 that runs fine. This is the part of the script
that is causing problems (line numbers are included).

24 PATH=$(ls -d './'$SET'/'$FOLD'/'$FOLD'_anneal/'$PARAM_SET'/'$AN_SET)
25 echo $PATH
26
27 FILE_LIST=($(ls $PATH'/'*'out.txt'))
28 echo ${FILE_LIST[@]}

The echo $PATH command gives the correct output, but I get the error on
line 27. I have tried without the double parentheses, which wouldn't
give the result I want,

FILE_LIST=$(ls $PATH'/'*'out.txt')

but this gives the same error.

After this problem happened, I updated cygwin and restarted, but the
issue persists. Is there something wrong with my cygwin install? If
there happens to be some problem with my bash, please let me know, but
this is pretty simple stuff and I just can't see why ls would be found
at line 24 but not line 27.

The test script worked many times before this error and I didn't change
that part of the script that is causing the error.

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: cygwin bash script suddenly can't find ls, grep
  2014-10-12  0:05 cygwin bash script suddenly can't find ls, grep LMH
@ 2014-10-12  0:17 ` Ken Brown
  2014-10-12  0:30   ` LMH
  0 siblings, 1 reply; 8+ messages in thread
From: Ken Brown @ 2014-10-12  0:17 UTC (permalink / raw)
  To: cygwin

On 10/11/2014 8:04 PM, LMH wrote:
> Hello,
>
> I have been working on a bash script and suddenly I started getting an
> error that ls could not be found,
>
> ./remove_rows.sh: line 27: ls: command not found
>
> I can run ls from the command line just fine. There is also an ls
> command before line 27 that runs fine. This is the part of the script
> that is causing problems (line numbers are included).
>
> 24 PATH=$(ls -d './'$SET'/'$FOLD'/'$FOLD'_anneal/'$PARAM_SET'/'$AN_SET)
> 25 echo $PATH
> 26
> 27 FILE_LIST=($(ls $PATH'/'*'out.txt'))
> 28 echo ${FILE_LIST[@]}
>
> The echo $PATH command gives the correct output, but I get the error on
> line 27. I have tried without the double parentheses, which wouldn't
> give the result I want,
>
> FILE_LIST=$(ls $PATH'/'*'out.txt')
>
> but this gives the same error.
>
> After this problem happened, I updated cygwin and restarted, but the
> issue persists. Is there something wrong with my cygwin install? If
> there happens to be some problem with my bash, please let me know, but
> this is pretty simple stuff and I just can't see why ls would be found
> at line 24 but not line 27.

You've changed PATH in line 24.  Is 'ls' still in it?

Ken


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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: cygwin bash script suddenly can't find ls, grep
  2014-10-12  0:17 ` Ken Brown
@ 2014-10-12  0:30   ` LMH
  2014-10-12  6:08     ` Achim Gratz
  2014-10-12  8:34     ` Thorsten Kampe
  0 siblings, 2 replies; 8+ messages in thread
From: LMH @ 2014-10-12  0:30 UTC (permalink / raw)
  To: cygwin



Ken Brown wrote:
> On 10/11/2014 8:04 PM, LMH wrote:
>> Hello,
>>
>> I have been working on a bash script and suddenly I started getting an
>> error that ls could not be found,
>>
>> ./remove_rows.sh: line 27: ls: command not found
>>
>> I can run ls from the command line just fine. There is also an ls
>> command before line 27 that runs fine. This is the part of the script
>> that is causing problems (line numbers are included).
>>
>> 24 PATH=$(ls -d './'$SET'/'$FOLD'/'$FOLD'_anneal/'$PARAM_SET'/'$AN_SET)
>> 25 echo $PATH
>> 26
>> 27 FILE_LIST=($(ls $PATH'/'*'out.txt'))
>> 28 echo ${FILE_LIST[@]}
>>
>> The echo $PATH command gives the correct output, but I get the error on
>> line 27. I have tried without the double parentheses, which wouldn't
>> give the result I want,
>>
>> FILE_LIST=$(ls $PATH'/'*'out.txt')
>>
>> but this gives the same error.
>>
>> After this problem happened, I updated cygwin and restarted, but the
>> issue persists. Is there something wrong with my cygwin install? If
>> there happens to be some problem with my bash, please let me know, but
>> this is pretty simple stuff and I just can't see why ls would be found
>> at line 24 but not line 27.
> 
> You've changed PATH in line 24.  Is 'ls' still in it?
> 
> Ken

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.

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: cygwin bash script suddenly can't find ls, grep
  2014-10-12  0:30   ` LMH
@ 2014-10-12  6:08     ` Achim Gratz
  2014-10-14 20:53       ` LMH
  2014-10-12  8:34     ` Thorsten Kampe
  1 sibling, 1 reply; 8+ messages in thread
From: Achim Gratz @ 2014-10-12  6:08 UTC (permalink / raw)
  To: cygwin

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.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Factory and User Sound Singles for Waldorf Blofeld:
http://Synth.Stromeko.net/Downloads.html#WaldorfSounds

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: cygwin bash script suddenly can't find ls, grep
  2014-10-12  0:30   ` LMH
  2014-10-12  6:08     ` Achim Gratz
@ 2014-10-12  8:34     ` Thorsten Kampe
  2014-10-14 20:54       ` LMH
  1 sibling, 1 reply; 8+ messages in thread
From: Thorsten Kampe @ 2014-10-12  8:34 UTC (permalink / raw)
  To: cygwin

* LMH (Sat, 11 Oct 2014 20:30:07 -0400)
> 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[@]}

That looks pretty ugly. You probably can replace all that with 

FILE_LIST=(./$SET/$FOLD/$FOLD_anneal/$PARAM_SET/$AN_SET/*out.txt)

Thorsten


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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: cygwin bash script suddenly can't find ls, grep
  2014-10-12  6:08     ` Achim Gratz
@ 2014-10-14 20:53       ` LMH
  0 siblings, 0 replies; 8+ messages in thread
From: LMH @ 2014-10-14 20:53 UTC (permalink / raw)
  To: cygwin

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: cygwin bash script suddenly can't find ls, grep
  2014-10-12  8:34     ` Thorsten Kampe
@ 2014-10-14 20:54       ` LMH
  2014-10-15  9:41         ` Robert Klemme
  0 siblings, 1 reply; 8+ messages in thread
From: LMH @ 2014-10-14 20:54 UTC (permalink / raw)
  To: cygwin

Thorsten Kampe wrote:
> * LMH (Sat, 11 Oct 2014 20:30:07 -0400)
>> 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[@]}
> 
> That looks pretty ugly. You probably can replace all that with 
> 
> FILE_LIST=(./$SET/$FOLD/$FOLD_anneal/$PARAM_SET/$AN_SET/*out.txt)
> 
> Thorsten
> 
> 
> --
> 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
> 
> 

Thank you for the suggestion. I have mad an additional post in response
to the previous message that addresses your suggestion as well.

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: cygwin bash script suddenly can't find ls, grep
  2014-10-14 20:54       ` LMH
@ 2014-10-15  9:41         ` Robert Klemme
  0 siblings, 0 replies; 8+ messages in thread
From: Robert Klemme @ 2014-10-15  9:41 UTC (permalink / raw)
  To: cygwin

On Tue, Oct 14, 2014 at 10:54 PM, LMH <lmh_users-groups@molconn.com> wrote:
> Thorsten Kampe wrote:
>> * LMH (Sat, 11 Oct 2014 20:30:07 -0400)
>>> 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[@]}
>>
>> That looks pretty ugly. You probably can replace all that with
>>
>> FILE_LIST=(./$SET/$FOLD/$FOLD_anneal/$PARAM_SET/$AN_SET/*out.txt)

More suggestions:

1. use lowercase variable names for variables used only inside your
script. Since variable names are case insensitive it will avoid
collisions like this and also improve readability of the code.
2. In bash you can set shell option "nullglob" to avoid a one element
array with the glob pattern if there is no matching file. In zsh it's
"setopt NULL_GLOB" I believe.
3. Since we do not know whether there are spaces in variables I would
replace the line above with (including suggestion 1):

file_list=("$set/$fold/$fold_anneal/$param_set/$an_set"/*out.txt)

Kind regards

robert


-- 
[guy, jim].each {|him| remember.him do |as, often| as.you_can - without end}
http://blog.rubybestpractices.com/

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-10-15  9:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-12  0:05 cygwin bash script suddenly can't find ls, grep LMH
2014-10-12  0:17 ` Ken Brown
2014-10-12  0:30   ` LMH
2014-10-12  6:08     ` Achim Gratz
2014-10-14 20:53       ` LMH
2014-10-12  8:34     ` Thorsten Kampe
2014-10-14 20:54       ` LMH
2014-10-15  9:41         ` Robert Klemme

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).