Welcome to Soft32 Linux Forums!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Strange bash / ls / ext / whatever problem

 
   Soft32 Home -> Linux -> Genreal Discussions RSS
Next:  RFS: libpam-storepw  
Author Message
Alexander Gran

External


Since: Oct 22, 2009
Posts: 3



(Msg. 1) Posted: Wed Oct 21, 2009 7:20 pm
Post subject: Strange bash / ls / ext / whatever problem
Archived from groups: comp>os>linux>misc (more info?)

Hi,

can someone explain this behaviour:

downloads:~# mkdir test
downloads:~# cd test
downloads:~/test# touch a
downloads:~/test# for i in `ls`; do ls $i ; done
ls: cannot access a: No such file or directory
ls: cannot access : No such file or directory
downloads:~/test# ls a
a

I thought it might be an IFS issue, but that one is unset.
System is quite plain debian lenny. FS is ext3, checked.
Using dash everything works:

downloads:~/test# /bin/sh
\h:\w$ cd /root/test
\h:\w$ for i in `ls`; do ls $i ; done
a

regards
Alex
Back to top
Login to vote
Alexander Gran

External


Since: Oct 22, 2009
Posts: 3



(Msg. 2) Posted: Wed Oct 21, 2009 7:20 pm
Post subject: Re: Strange bash / ls / ext / whatever problem [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Alexander Gran wrote:

> downloads:~# mkdir test
> downloads:~# cd test
> downloads:~/test# touch a
> downloads:~/test# for i in `ls`; do ls $i ; done
> ls: cannot access a: No such file or directory
> ls: cannot access : No such file or directory
> downloads:~/test# ls a
> a
>
> I thought it might be an IFS issue, but that one is unset.
> System is quite plain debian lenny. FS is ext3, checked.
> Using dash everything works:
>
> downloads:~/test# /bin/sh
> \h:\w$ cd /root/test
> \h:\w$ for i in `ls`; do ls $i ; done
> a

alright, solved thatone (as usual, just seconds after posting...)
For every googler who has the same issue.
The cause is that ls output is broken, as LS_OPTIONS=--color=always --human
is set. Setting it to LS_OPTIONS='--color=auto --human' fixes the issue.
Now I only need to find out who settet it to always...

regards
Alex
Back to top
Login to vote
Allen Kistler

External


Since: Jul 12, 2004
Posts: 94



(Msg. 3) Posted: Wed Oct 21, 2009 7:20 pm
Post subject: Re: Strange bash / ls / ext / whatever problem [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Alexander Gran wrote:
> can someone explain this behaviour:
>
> downloads:~# mkdir test
> downloads:~# cd test
> downloads:~/test# touch a
> downloads:~/test# for i in `ls`; do ls $i ; done
> ls: cannot access a: No such file or directory
> ls: cannot access : No such file or directory
> downloads:~/test# ls a
> a
>
> I thought it might be an IFS issue, but that one is unset.
> System is quite plain debian lenny. FS is ext3, checked.
> Using dash everything works:
>
> downloads:~/test# /bin/sh
> \h:\w$ cd /root/test
> \h:\w$ for i in `ls`; do ls $i ; done
> a

Works for me in bash. Do you have ls aliased to something?

Is it enlightening to try
set -o xtrace
before you run the for loop?

set +o xtrace
to turn off xtrace.
Back to top
Login to vote
Grant

External


Since: Nov 02, 2008
Posts: 81



(Msg. 4) Posted: Wed Oct 21, 2009 9:20 pm
Post subject: Re: Strange bash / ls / ext / whatever problem [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Thu, 22 Oct 2009 01:44:56 +0200, Alexander Gran <alex DeleteThis @grans.eu> wrote:

>Hi,
>
>can someone explain this behaviour:
>
>downloads:~# mkdir test
>downloads:~# cd test
>downloads:~/test# touch a
>downloads:~/test# for i in `ls`; do ls $i ; done
>ls: cannot access a: No such file or directory
>ls: cannot access : No such file or directory
>downloads:~/test# ls a
>a

Works fine here, on bash shell:

grant@deltree:~$ mkdir test
grant@deltree:~$ cd test/
grant@deltree:~/test$ touch a
grant@deltree:~/test$ for i in `ls`; do ls $i ; done
a

On slackware-11.

Grant.
--
http://bugsplatter.id.au
Back to top
Login to vote
The Natural Philosopher

External


Since: Apr 15, 2009
Posts: 97



(Msg. 5) Posted: Wed Oct 21, 2009 9:20 pm
Post subject: Re: Strange bash / ls / ext / whatever problem [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Grant wrote:
> On Thu, 22 Oct 2009 01:44:56 +0200, Alexander Gran <alex.DeleteThis@grans.eu> wrote:
>
>> Hi,
>>
>> can someone explain this behaviour:
>>
>> downloads:~# mkdir test
>> downloads:~# cd test
>> downloads:~/test# touch a
>> downloads:~/test# for i in `ls`; do ls $i ; done
>> ls: cannot access a: No such file or directory
>> ls: cannot access : No such file or directory
>> downloads:~/test# ls a
>> a
>
> Works fine here, on bash shell:
>
> grant@deltree:~$ mkdir test
> grant@deltree:~$ cd test/
> grant@deltree:~/test$ touch a
> grant@deltree:~/test$ for i in `ls`; do ls $i ; done
> a
>
> On slackware-11.
>
> Grant.
only time i've seen similar is when in a CIFS mounted directory.
Back to top
Login to vote
Henning Bekel

External


Since: Oct 22, 2009
Posts: 1



(Msg. 6) Posted: Thu Oct 22, 2009 11:20 am
Post subject: Re: Strange bash / ls / ext / whatever problem [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Alexander Gran wrote:

> Alexander Gran wrote:
>
>> downloads:~# mkdir test
>> downloads:~# cd test
>> downloads:~/test# touch a
>> downloads:~/test# for i in `ls`; do ls $i ; done
>> ls: cannot access a: No such file or directory
>> ls: cannot access : No such file or directory
>> downloads:~/test# ls a
>> a
>>
>> I thought it might be an IFS issue, but that one is unset.
>> System is quite plain debian lenny. FS is ext3, checked.
>> Using dash everything works:
>>
>> downloads:~/test# /bin/sh
>> \h:\w$ cd /root/test
>> \h:\w$ for i in `ls`; do ls $i ; done
>> a
>
> alright, solved thatone (as usual, just seconds after
> posting...) For every googler who has the same issue.
> The cause is that ls output is broken, as
> LS_OPTIONS=--color=always --human is set. Setting it to
> LS_OPTIONS='--color=auto --human' fixes the issue. Now I only
> need to find out who settet it to always...
>
> regards
> Alex

Don't use ls in the first place, at least not for retrieving a
list of directory entries to iterate over. Your script will still
fail for entries containing spaces, since the result of `ls` will
be subject to word splitting in bash. Use a glob instead:

for i in *; do echo $i; done

Entries won't be split into words in this case, and you won't have
to rely on an external command being set up just the way you need
it.

Regards,
Henning
Back to top
Login to vote
Alexander Gran

External


Since: Oct 22, 2009
Posts: 3



(Msg. 7) Posted: Thu Oct 22, 2009 7:20 pm
Post subject: Re: Strange bash / ls / ext / whatever problem [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Henning Bekel wrote:

> Don't use ls in the first place, at least not for retrieving a
> list of directory entries to iterate over. Your script will still
> fail for entries containing spaces, since the result of `ls` will
> be subject to word splitting in bash. Use a glob instead:
>
> for i in *; do echo $i; done
>
> Entries won't be split into words in this case, and you won't have
> to rely on an external command being set up just the way you need
> it.

Yeah, I know. I just posted a very simplified example, the whole story was
to complex. Acutally I found the soultion but reducing the example size even
more, because a
ls a > testout
vi testout
showed me what happend.

regards
Alex
Back to top
Login to vote
Display posts from previous:   
Related Topics:
ImageMagick Problem - Hi, On kjg-heiligenstein.de i am using PHPix for creating the image galleries. The Script uses ImageMagick for..

acl and linux - hi, i have to work with acl and linux; how is the best file system to do it ? (i have heard reiserfs but i don't know....

Microsoft/LINUX debate. - Why does people brother having this Microsoft/LINUX mud-slinging thing? I am new to LINUX but installed REDHAT 8..

Multiple CD volume backup solution - Hi all I'm looking for a backup package that will allow me to span multiple CDs and also allow for individual CD..

virus scanner - Hi All was wondering if i can get some idea of what people are useing for virus scanners on Redhat 8. Its sendmail tha...

trailing slash in web urls - ya this may be a lame question but i have just setup apache 2.0.46 and when i connect to http://domain it gets the..
       Soft32 Home -> Linux -> Genreal Discussions All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Categories:
 Windows
  Linux
 Mac
 PDA


[ Contact us | Terms of Service/Privacy Policy ]