Re: [gentoo-user] Question about handling filenames with "illegal" characters...

2020-04-16 Thread Michael Orlitzky
On 4/16/20 11:15 AM, tu...@posteo.de wrote:
> 
> Is there a way to express $fn in a way, so that
> do_something get one filename at a time and
> whole thing does not is torn apart by some
> not so nice filenames?
> 

What are your constraints... are you using bash, or just any POSIX
shell? Can you rely on GNU extensions to find/xargs, etc? Is
do_something a shell command or a program?

Even with bash, find/xargs tends to fall down if you need to run a
series of shell commands on each thing found. The simplest way to handle
that is to use "while read..." with the bash-specific null separator to
loop through the files one at a time, like in

https://gitweb.gentoo.org/proj/portage.git/tree/bin/install-qa-check.d/90bad-bin-owner

If you want it to be portable, on the other hand, I recently wasted
several hours on this problem and it's not pretty. Something like,

  find -name 'whatever' \
-exec sh -c "
  for f in \"\${@}\"; do
do_stuff \"\${f}\" && echo \"\${f}\"
  done
" - {} +

will do it.



Re: [gentoo-user] Question about handling filenames with "illegal" characters...

2020-04-16 Thread tuxic
On 04/16 05:21, Francesco Turco wrote:
> On Thu, Apr 16, 2020, at 17:15, tu...@posteo.de wrote:
> > Normally I would replace the asd* with the according
> > 
> > find . -name 'asd*' -print0 | 
> > 
> > but I got in trpuble, because "do_something" 
> > now misunderstood the whole thing.
> 
> What about the following command?
> 
> find . -name 'asd*' -print0 | xargs -0 
> 
> -- 
> https://fturco.net/
> 

I would do that normally, but the  to much "more"





Re: [gentoo-user] Question about handling filenames with "illegal" characters...

2020-04-16 Thread tuxic
On 04/16 11:29, Rich Freeman wrote:
> On Thu, Apr 16, 2020 at 11:19 AM Neil Bothwick  wrote:
> >
> > On Thu, 16 Apr 2020 17:15:45 +0200, tu...@posteo.de wrote:
> >
> > > a loop like this
> > >
> > > for fn in asd* ; do
> > > do_something $fn
> > > done
> > >
> > > fails, when a file is named like this:
> > >
> > > List of OSses allowing spaces in filenames.txt
> > >
> >
> > do_something "$fn"
> >
> 
> That, or use ${fn} - that might be more resistant to quotes in
> filenames though I haven't looked closely into that.
> 
> If you look at most ebuilds they're full of quoted or braced variables
> for exactly this reason.  If you want to stick spaces in your
> directory paths that is your mess to deal with, but Gentoo won't
> break.
> 
> On a side note, if you have a directory full of crufty filenames the
> detox program is very useful for cleaning them up.  Of course, that is
> invasive and you probably don't want to rely on that in your script.
> 
> -- 
> Rich
> 

Hi Rich,

these [CENSORED] filenames are mainly copies from the contents of
usbstick, which were previoysly filled using machines, which were
neither UNICES nor Linuxxes nor MacOSxxes ... you know what I mean.
I myself stick to sane filenames. 

Detox is known to me. But for certain reasons I cannot change the
filenames now...I have to process them first.

Cheers!
Meino





Re: [gentoo-user] Question about handling filenames with "illegal" characters...

2020-04-16 Thread Rich Freeman
On Thu, Apr 16, 2020 at 11:19 AM Neil Bothwick  wrote:
>
> On Thu, 16 Apr 2020 17:15:45 +0200, tu...@posteo.de wrote:
>
> > a loop like this
> >
> > for fn in asd* ; do
> > do_something $fn
> > done
> >
> > fails, when a file is named like this:
> >
> > List of OSses allowing spaces in filenames.txt
> >
>
> do_something "$fn"
>

That, or use ${fn} - that might be more resistant to quotes in
filenames though I haven't looked closely into that.

If you look at most ebuilds they're full of quoted or braced variables
for exactly this reason.  If you want to stick spaces in your
directory paths that is your mess to deal with, but Gentoo won't
break.

On a side note, if you have a directory full of crufty filenames the
detox program is very useful for cleaning them up.  Of course, that is
invasive and you probably don't want to rely on that in your script.

-- 
Rich



Re: [gentoo-user] Question about handling filenames with "illegal" characters...

2020-04-16 Thread tuxic
On 04/16 04:19, Neil Bothwick wrote:
> On Thu, 16 Apr 2020 17:15:45 +0200, tu...@posteo.de wrote:
> 
> > a loop like this
> > 
> > for fn in asd* ; do
> > do_something $fn
> > done
> > 
> > fails, when a file is named like this:
> > 
> > List of OSses allowing spaces in filenames.txt
> > 
> 
> do_something "$fn"
> 
> Would this work?
> 
> 
> -- 
> Neil Bothwick
> 
> C:\BELFRY is where I keep my .BAT files ^^^oo^^^


Hi Neil,

is this the "Bothwick effect" ?

This was the first I tried after my script failed...and it failed
again after adding the "".
I tried it again...and now it works. 
Only difference: I did it from the commandline (using zsh).

I am baffled.

But it is better, I don't completely understand, whu it is working
now than vice versa ;)

Cheers!
Meino






Re: [gentoo-user] Question about handling filenames with "illegal" characters...

2020-04-16 Thread Francesco Turco
On Thu, Apr 16, 2020, at 17:15, tu...@posteo.de wrote:
> Normally I would replace the asd* with the according
> 
> find . -name 'asd*' -print0 | 
> 
> but I got in trpuble, because "do_something" 
> now misunderstood the whole thing.

What about the following command?

find . -name 'asd*' -print0 | xargs -0 

-- 
https://fturco.net/



Re: [gentoo-user] Question about handling filenames with "illegal" characters...

2020-04-16 Thread Neil Bothwick
On Thu, 16 Apr 2020 17:15:45 +0200, tu...@posteo.de wrote:

> a loop like this
> 
> for fn in asd* ; do
> do_something $fn
> done
> 
> fails, when a file is named like this:
> 
> List of OSses allowing spaces in filenames.txt
> 

do_something "$fn"

Would this work?


-- 
Neil Bothwick

C:\BELFRY is where I keep my .BAT files ^^^oo^^^


pgpBgO940ccyi.pgp
Description: OpenPGP digital signature