Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

A fail-safe circuit will destroy others. -- Klipstein


computers / comp.os.linux.misc / Piping commands to a shell but keeping interactivity

SubjectAuthor
* Piping commands to a shell but keeping interactivityJames Harris
+* Re: Piping commands to a shell but keeping interactivityRalf Fassel
|`- Re: Piping commands to a shell but keeping interactivityJames Harris
`* Re: Piping commands to a shell but keeping interactivityJohn-Paul Stewart
 `* Re: Piping commands to a shell but keeping interactivityRich
  `* Re: Piping commands to a shell but keeping interactivityRichard Kettlewell
   `* Re: Piping commands to a shell but keeping interactivityJohn-Paul Stewart
    +* Re: Piping commands to a shell but keeping interactivityJames Harris
    |+- Re: Piping commands to a shell but keeping interactivityLawrence D'Oliveiro
    |`* Re: Piping commands to a shell but keeping interactivityRich
    | `* Re: Piping commands to a shell but keeping interactivityJames Harris
    |  `- Re: Piping commands to a shell but keeping interactivityRich
    `* Re: Piping commands to a shell but keeping interactivityFritz Wuehler
     +- Re: Piping commands to a shell but keeping interactivitycandycanearter07
     `- Re: Piping commands to a shell but keeping interactivityJames Harris

1
Piping commands to a shell but keeping interactivity

<urhjc6$2enkl$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=14693&group=comp.os.linux.misc#14693

  copy link   Newsgroups: comp.os.linux.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: james.harris.1@gmail.com (James Harris)
Newsgroups: comp.os.linux.misc
Subject: Piping commands to a shell but keeping interactivity
Date: Mon, 26 Feb 2024 08:50:13 +0000
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <urhjc6$2enkl$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 26 Feb 2024 08:50:14 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="bd34b55b2df01ac04adcf2f9315e7b4e";
logging-data="2580117"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19zATxXcDed/Bv3yp500KOyeZLTj7s0HkA="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:xNf3XQcDZkLf765Q9hLe/WonyV8=
Content-Language: en-GB
 by: James Harris - Mon, 26 Feb 2024 08:50 UTC

It can be very useful to pipe commands into a shell such as with

ls sample* | sed 's/^/rm -v /' | sh

That works, finding all the files which match the pattern and converting
them into commands which it then executes. (In reality I have a piece of
code which generates the file names but ls is a simpler example which
shows the germane part of the mechanism.)

However, if I add the -i option to rm as in

ls sample* | sed 's/^/rm -iv /' | sh

then it doesn't work, printing all the questions on one line and not
waiting for a response:

rm: remove regular empty file 'sample3'? rm: remove regular empty file
'sample7'? $

I presumed that's because sh has only stdin as its input stream.
However, consider this:

sh <(ls sample* | sed 's/^/rm -iv /')

That does work:

$ sh <(ls sample* | sed 's/^/rm -iv /')
rm: remove regular file 'sample3'? n
rm: remove regular file 'sample7'? n
$

Anyone know why the latter example is different? And is there a way to
change the command to put sh at the end rather than the beginning?

--
James Harris

Re: Piping commands to a shell but keeping interactivity

<ygasf1fl5f6.fsf@panther.akutech-local.de>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=14694&group=comp.os.linux.misc#14694

  copy link   Newsgroups: comp.os.linux.misc
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralfixx@gmx.de (Ralf Fassel)
Newsgroups: comp.os.linux.misc
Subject: Re: Piping commands to a shell but keeping interactivity
Date: Mon, 26 Feb 2024 14:29:49 +0100
Lines: 53
Message-ID: <ygasf1fl5f6.fsf@panther.akutech-local.de>
References: <urhjc6$2enkl$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net HLbgbQk81KKHapAfiKnMFQBKTJUEJc9w4TxbDJBSO8FN4z8T4=
Cancel-Lock: sha1:wGTmUjVVqMIIEiQG3LpY2EKutVA= sha1:qSXrgJ+m8YlL07fT7ivfR86QMPc= sha256:pKpzoqvPvGgF02wG+g9WytleFFCuEhXtQtZR9u5mggQ=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
 by: Ralf Fassel - Mon, 26 Feb 2024 13:29 UTC

* James Harris <james.harris.1@gmail.com>
| However, if I add the -i option to rm as in
>
| ls sample* | sed 's/^/rm -iv /' | sh
>
| then it doesn't work, printing all the questions on one line and not
| waiting for a response:
>
| rm: remove regular empty file 'sample3'? rm: remove regular empty file
| 'sample7'? $
>
| I presumed that's because sh has only stdin as its input
| stream.

Correct.

| However, consider this:
>
| sh <(ls sample* | sed 's/^/rm -iv /')
>
| That does work:
>
| $ sh <(ls sample* | sed 's/^/rm -iv /')
| rm: remove regular file 'sample3'? n
| rm: remove regular file 'sample7'? n
| $
>
| Anyone know why the latter example is different? And is there a way to
| change the command to put sh at the end rather than the beginning?

Because <(cmd) produces a (temporary) file name which is added to the
cmd as first argument (cf. "man bash"). Therefore the command executed
is actually

sh filename

where stdin is still available.

Process Substitution
Process substitution allows a process's input or output to be referred
to using a filename. It takes the form of <(list) or >(list). The
process list is run asynchronously, and its input or output appears as
a filename. This filename is passed as an argument to the current com-
mand as the result of the expansion. [...] If the <(list) form
is used, the file passed as an argument should be read to obtain the
output of list.

cf.
$ echo <(ls)
/dev/fd/63

HTH
R'

Re: Piping commands to a shell but keeping interactivity

<l44pliF6eejU2@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=14700&group=comp.os.linux.misc#14700

  copy link   Newsgroups: comp.os.linux.misc
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: jpstewart@personalprojects.net (John-Paul Stewart)
Newsgroups: comp.os.linux.misc
Subject: Re: Piping commands to a shell but keeping interactivity
Date: Mon, 26 Feb 2024 19:45:38 -0500
Lines: 10
Message-ID: <l44pliF6eejU2@mid.individual.net>
References: <urhjc6$2enkl$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net qnCOA8IdSH7lXyHiSbIbCQi3lLXHTPlJl5QiMFWSVm5OE0WIDx
Cancel-Lock: sha1:TdaWika6+468lIsREz7PBJUDvec= sha256:GcZFZqstxpr4Xm3UZjr7iZB54nKZSOR4xq2YzwqZHmU=
User-Agent: Mozilla Thunderbird
Content-Language: en-CA
In-Reply-To: <urhjc6$2enkl$1@dont-email.me>
 by: John-Paul Stewart - Tue, 27 Feb 2024 00:45 UTC

On 2024-02-26 3:50 a.m., James Harris wrote:
> It can be very useful to pipe commands into a shell such as with
>
>   ls sample* | sed 's/^/rm -v /' | sh

Can I ask why you pipe to sed and a shell instead of simply using xargs:

ls sample* | xargs rm -vi

That seems to be much a simpler solution.

Re: Piping commands to a shell but keeping interactivity

<urjj7j$3038r$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=14702&group=comp.os.linux.misc#14702

  copy link   Newsgroups: comp.os.linux.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: rich@example.invalid (Rich)
Newsgroups: comp.os.linux.misc
Subject: Re: Piping commands to a shell but keeping interactivity
Date: Tue, 27 Feb 2024 03:00:03 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <urjj7j$3038r$1@dont-email.me>
References: <urhjc6$2enkl$1@dont-email.me> <l44pliF6eejU2@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 27 Feb 2024 03:00:03 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="dc5e80828b331392eb04fa2e0267edf2";
logging-data="3149083"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+P7kU5NpoF6LuJ7vgioyfi"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:ipqJoPT1dia+GN4ioX8dVNAT9/8=
 by: Rich - Tue, 27 Feb 2024 03:00 UTC

John-Paul Stewart <jpstewart@personalprojects.net> wrote:
> On 2024-02-26 3:50 a.m., James Harris wrote:
>> It can be very useful to pipe commands into a shell such as with
>>
>>   ls sample* | sed 's/^/rm -v /' | sh
>
> Can I ask why you pipe to sed and a shell instead of simply using xargs:
>
> ls sample* | xargs rm -vi
>
> That seems to be much a simpler solution.

Even better, this version which won't choke on spaces or other odd
characters in filenames:

find -name sample\* -maxdepth 1 -print0 | xargs -0 rm -vi

Re: Piping commands to a shell but keeping interactivity

<wwvzfvmi9bp.fsf@LkoBDZeT.terraraq.uk>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=14703&group=comp.os.linux.misc#14703

  copy link   Newsgroups: comp.os.linux.misc
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!nntp.terraraq.uk!.POSTED.tunnel.sfere.anjou.terraraq.org.uk!not-for-mail
From: invalid@invalid.invalid (Richard Kettlewell)
Newsgroups: comp.os.linux.misc
Subject: Re: Piping commands to a shell but keeping interactivity
Date: Tue, 27 Feb 2024 08:46:02 +0000
Organization: terraraq NNTP server
Message-ID: <wwvzfvmi9bp.fsf@LkoBDZeT.terraraq.uk>
References: <urhjc6$2enkl$1@dont-email.me> <l44pliF6eejU2@mid.individual.net>
<urjj7j$3038r$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: innmantic.terraraq.uk; posting-host="tunnel.sfere.anjou.terraraq.org.uk:172.17.207.6";
logging-data="28915"; mail-complaints-to="usenet@innmantic.terraraq.uk"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:FIApz1AvNKfSyGF1h5kGpPxtlxo=
X-Face: h[Hh-7npe<<b4/eW[]sat,I3O`t8A`(ej.H!F4\8|;ih)`7{@:A~/j1}gTt4e7-n*F?.Rl^
F<\{jehn7.KrO{!7=:(@J~]<.[{>v9!1<qZY,{EJxg6?Er4Y7Ng2\Ft>Z&W?r\c.!4DXH5PWpga"ha
+r0NzP?vnz:e/knOY)PI-
X-Boydie: NO
 by: Richard Kettlewell - Tue, 27 Feb 2024 08:46 UTC

Rich <rich@example.invalid> writes:
> John-Paul Stewart <jpstewart@personalprojects.net> wrote:
>> On 2024-02-26 3:50 a.m., James Harris wrote:
>>> It can be very useful to pipe commands into a shell such as with
>>>
>>>   ls sample* | sed 's/^/rm -v /' | sh
>>
>> Can I ask why you pipe to sed and a shell instead of simply using xargs:
>>
>> ls sample* | xargs rm -vi
>>
>> That seems to be much a simpler solution.
>
> Even better, this version which won't choke on spaces or other odd
> characters in filenames:
>
> find -name sample\* -maxdepth 1 -print0 | xargs -0 rm -vi

That handles directories better too. But it doesn’t work, due to the
stdin issue that the OP was originally asking about.

The working answer is much simpler:

rm -vi sample*

The ‘ls’ versions will also behave quite badly in the face of
directories matching the pattern.

--
https://www.greenend.org.uk/rjk/

Re: Piping commands to a shell but keeping interactivity

<l47faiFkqi7U1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=14707&group=comp.os.linux.misc#14707

  copy link   Newsgroups: comp.os.linux.misc
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: jpstewart@personalprojects.net (John-Paul Stewart)
Newsgroups: comp.os.linux.misc
Subject: Re: Piping commands to a shell but keeping interactivity
Date: Tue, 27 Feb 2024 20:07:30 -0500
Lines: 33
Message-ID: <l47faiFkqi7U1@mid.individual.net>
References: <urhjc6$2enkl$1@dont-email.me> <l44pliF6eejU2@mid.individual.net>
<urjj7j$3038r$1@dont-email.me> <wwvzfvmi9bp.fsf@LkoBDZeT.terraraq.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net FuNWhBWzSY96XFWSMp1v8gC6P3dgMuaGXH/mZWSB9ZrC2xN/lL
Cancel-Lock: sha1:ojv/CKXzDJwlmZhO4X9WEMEXdbQ= sha256:IAud6HyXzzBu1krbSOsJPCw6fH83usx8RySSkG9XBXY=
User-Agent: Mozilla Thunderbird
Content-Language: en-CA
In-Reply-To: <wwvzfvmi9bp.fsf@LkoBDZeT.terraraq.uk>
 by: John-Paul Stewart - Wed, 28 Feb 2024 01:07 UTC

On 2024-02-27 3:46 a.m., Richard Kettlewell wrote:
> Rich <rich@example.invalid> writes:
>> John-Paul Stewart <jpstewart@personalprojects.net> wrote:
>>> On 2024-02-26 3:50 a.m., James Harris wrote:
>>>> It can be very useful to pipe commands into a shell such as with
>>>>
>>>>   ls sample* | sed 's/^/rm -v /' | sh
>>>
>>> Can I ask why you pipe to sed and a shell instead of simply using xargs:
>>>
>>> ls sample* | xargs rm -vi
>>>
>>> That seems to be much a simpler solution.
>>
>> Even better, this version which won't choke on spaces or other odd
>> characters in filenames:
>>
>> find -name sample\* -maxdepth 1 -print0 | xargs -0 rm -vi
>
> That handles directories better too. But it doesn’t work, due to the
> stdin issue that the OP was originally asking about.
>
> The working answer is much simpler:
>
> rm -vi sample*
>
> The ‘ls’ versions will also behave quite badly in the face of
> directories matching the pattern.

Well, the OP did say that 'ls' was just an example. In reality it is
some other code that generates the list of names.

Re: Piping commands to a shell but keeping interactivity

<uscoid$14l6b$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=14725&group=comp.os.linux.misc#14725

  copy link   Newsgroups: comp.os.linux.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: james.harris.1@gmail.com (James Harris)
Newsgroups: comp.os.linux.misc
Subject: Re: Piping commands to a shell but keeping interactivity
Date: Thu, 7 Mar 2024 16:04:26 +0000
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <uscoid$14l6b$1@dont-email.me>
References: <urhjc6$2enkl$1@dont-email.me>
<ygasf1fl5f6.fsf@panther.akutech-local.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 7 Mar 2024 16:04:29 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="33e2f447396ef8b3bedb5898ffdfd2de";
logging-data="1201355"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX184IaH3qkrfbtjUwe6hRmrLaFXwjuUkZ5w="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:GvG6D6rH209g269Linl1iPR4hLc=
In-Reply-To: <ygasf1fl5f6.fsf@panther.akutech-local.de>
Content-Language: en-GB
 by: James Harris - Thu, 7 Mar 2024 16:04 UTC

On 26/02/2024 13:29, Ralf Fassel wrote:
> * James Harris <james.harris.1@gmail.com>

....

> | Anyone know why the latter example is different? And is there a way to
> | change the command to put sh at the end rather than the beginning?
>
> Because <(cmd) produces a (temporary) file name which is added to the
> cmd as first argument (cf. "man bash"). Therefore the command executed
> is actually
>
> sh filename
>
> where stdin is still available.
>
> Process Substitution
> Process substitution allows a process's input or output to be referred
> to using a filename. It takes the form of <(list) or >(list). The
> process list is run asynchronously, and its input or output appears as
> a filename. This filename is passed as an argument to the current com-
> mand as the result of the expansion. [...] If the <(list) form
> is used, the file passed as an argument should be read to obtain the
> output of list.

Thanks. That's very clear.

--
James Harris

Re: Piping commands to a shell but keeping interactivity

<uscpnt$14tr1$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=14726&group=comp.os.linux.misc#14726

  copy link   Newsgroups: comp.os.linux.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: james.harris.1@gmail.com (James Harris)
Newsgroups: comp.os.linux.misc
Subject: Re: Piping commands to a shell but keeping interactivity
Date: Thu, 7 Mar 2024 16:24:26 +0000
Organization: A noiseless patient Spider
Lines: 67
Message-ID: <uscpnt$14tr1$1@dont-email.me>
References: <urhjc6$2enkl$1@dont-email.me> <l44pliF6eejU2@mid.individual.net>
<urjj7j$3038r$1@dont-email.me> <wwvzfvmi9bp.fsf@LkoBDZeT.terraraq.uk>
<l47faiFkqi7U1@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 7 Mar 2024 16:24:29 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="33e2f447396ef8b3bedb5898ffdfd2de";
logging-data="1210209"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19UEcuMjuqzgnlamFtGbx2g+vDQwgLjq+8="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:kf3HbVJWCMk69jFPzn+5jX7grFk=
In-Reply-To: <l47faiFkqi7U1@mid.individual.net>
Content-Language: en-GB
 by: James Harris - Thu, 7 Mar 2024 16:24 UTC

On 28/02/2024 01:07, John-Paul Stewart wrote:
> On 2024-02-27 3:46 a.m., Richard Kettlewell wrote:
>> Rich <rich@example.invalid> writes:
>>> John-Paul Stewart <jpstewart@personalprojects.net> wrote:
>>>> On 2024-02-26 3:50 a.m., James Harris wrote:
>>>>> It can be very useful to pipe commands into a shell such as with
>>>>>
>>>>>   ls sample* | sed 's/^/rm -v /' | sh
>>>>
>>>> Can I ask why you pipe to sed and a shell instead of simply using xargs:
>>>>
>>>> ls sample* | xargs rm -vi
>>>>
>>>> That seems to be much a simpler solution.
>>>
>>> Even better, this version which won't choke on spaces or other odd
>>> characters in filenames:
>>>
>>> find -name sample\* -maxdepth 1 -print0 | xargs -0 rm -vi
>>
>> That handles directories better too. But it doesn’t work, due to the
>> stdin issue that the OP was originally asking about.
>>
>> The working answer is much simpler:
>>
>> rm -vi sample*
>>
>> The ‘ls’ versions will also behave quite badly in the face of
>> directories matching the pattern.
>
> Well, the OP did say that 'ls' was just an example. In reality it is
> some other code that generates the list of names.

That's right. What this is for is code to list files in a folder which
are duplicates of those in another folder (same name, same relative
place in the folder hierarchy, etc). For example, say there are two
folders, c and d, and one is potentially a copy of the other. The command

$ ./lsdup.py -r c d

lists files in d (and subdirectories due to the -r recurse option) which
are duplicates of those in c.

In answer to your other point about using xargs, I would use it if it
would do what's required, and do so consistently, but I am not sure
whether I can trust it or not. Here's a full example.

$ ./lsdup.py c d -r | sed 's/^/rm -v /'

which generates commands such as

rm -v 'd/contentsame.txt'
rm -v 'd/hardlink.txt'
rm -v 'd/subdir/filesame.txt'

Once the commands have been checked, if required, I pipe them into sh to
actually delete the files. (A separate command, lsempty.py, is is used
to delete the resultant empty folders.)

In answer to the point about filenames with spaces and odd characters, I
currently output names in single quotes, as above.

--
James Harris

Re: Piping commands to a shell but keeping interactivity

<usdiok$1a50p$3@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=14727&group=comp.os.linux.misc#14727

  copy link   Newsgroups: comp.os.linux.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.os.linux.misc
Subject: Re: Piping commands to a shell but keeping interactivity
Date: Thu, 7 Mar 2024 23:31:33 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <usdiok$1a50p$3@dont-email.me>
References: <urhjc6$2enkl$1@dont-email.me> <l44pliF6eejU2@mid.individual.net>
<urjj7j$3038r$1@dont-email.me> <wwvzfvmi9bp.fsf@LkoBDZeT.terraraq.uk>
<l47faiFkqi7U1@mid.individual.net> <uscpnt$14tr1$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 7 Mar 2024 23:31:33 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d5f167ea8e6b66fd37103ff38661b22f";
logging-data="1381401"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/onpi4zeI8wNjb5x+tVMms"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:DSx+IgylQNP9wWObyh0S5z+qvQs=
 by: Lawrence D'Oliv - Thu, 7 Mar 2024 23:31 UTC

On Thu, 7 Mar 2024 16:24:26 +0000, James Harris wrote:

> In answer to your other point about using xargs, I would use it if it
> would do what's required, and do so consistently, but I am not sure
> whether I can trust it or not.

You mean, accidentally operating on the wrong files?

That’s quite easy to test: instead of

xargs «cmd...»

do

xargs echo «cmd...»

and check the output to see that it shows what you expect. Once you are
satisfied, you can run it again without the “echo”.

Re: Piping commands to a shell but keeping interactivity

<use1ac$1gd9k$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=14728&group=comp.os.linux.misc#14728

  copy link   Newsgroups: comp.os.linux.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: rich@example.invalid (Rich)
Newsgroups: comp.os.linux.misc
Subject: Re: Piping commands to a shell but keeping interactivity
Date: Fri, 8 Mar 2024 03:39:56 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 75
Message-ID: <use1ac$1gd9k$1@dont-email.me>
References: <urhjc6$2enkl$1@dont-email.me> <l44pliF6eejU2@mid.individual.net> <urjj7j$3038r$1@dont-email.me> <wwvzfvmi9bp.fsf@LkoBDZeT.terraraq.uk> <l47faiFkqi7U1@mid.individual.net> <uscpnt$14tr1$1@dont-email.me>
Injection-Date: Fri, 8 Mar 2024 03:39:56 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="bf3d41fe1c02e22eb6be3e60dd9819bc";
logging-data="1586484"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/QhgrObgZ+yFSRDj1LmLvE"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:hTxEgY6U5u3LTWG4YbzjwQ+xXLw=
 by: Rich - Fri, 8 Mar 2024 03:39 UTC

James Harris <james.harris.1@gmail.com> wrote:
> That's right. What this is for is code to list files in a folder
> which are duplicates of those in another folder (same name, same
> relative place in the folder hierarchy, etc). For example, say there
> are two folders, c and d, and one is potentially a copy of the other.
> The command
>
> $ ./lsdup.py -r c d
>
> lists files in d (and subdirectories due to the -r recurse option) which
> are duplicates of those in c.
>
> In answer to your other point about using xargs, I would use it if it
> would do what's required, and do so consistently,

It will, provided you output file names with ASCII null terminators
instead of ASCII newlines, and use the -0 option to tell xargs the
filenames are null separated.

> but I am not sure whether I can trust it or not.

You can. Provided you feed it ASCII null terminated filenames, it will
work properly, no matter what other weird characters might be in the
filenames.

> Here's a full example.
>
> $ ./lsdup.py c d -r | sed 's/^/rm -v /'
>
> which generates commands such as
>
> rm -v 'd/contentsame.txt'
> rm -v 'd/hardlink.txt'
> rm -v 'd/subdir/filesame.txt'

Provided you modified lsdup.py to output null terminated filenames, you
could do:

$ ./lsdup.py c d -r | xargs -0 rm -v

And the chosen files would be removed, no matter what odd characters or
spaces they might contain. Note that if you want to 'inspect' before
you delete, then you might want to add a "-0" option to lsdup.py to
toggle between ASCII newline and ASCII null terminators.

> Once the commands have been checked, if required, I pipe them into sh to
> actually delete the files.

xargs, with -0, into "rm" or "rm -v" will be much more efficient (i.e.,
faster) because xargs will call rm with the maximum number of files it
can pass per invocation, avoiding calling rm once per file, and
avoiding shell parsing to then fork and call rm, once per each file.

> (A separate command, lsempty.py, is is used to delete the resultant
> empty folders.)

A separate python command is completely unnecessary. Removing empty
leaf directories is already easy using the tools provided by the
system.:

$ find c d -type d -empty -print0 | xargs -0 rmdir

If you also want to remove parent empty directories should all their
children go away, change to:

$ find c d -type d -empty -print0 | xargs -0 rmdir -p

> In answer to the point about filenames with spaces and odd characters, I
> currently output names in single quotes, as above. This will
> complain until the parent is empty, but the complaints can be
> ignored.

Single quote is also a possible filename character, so if, by chance,
you end up with a file containing one ' somewhere your wrapping in
single quotes will result in a fail at that point.

Re: Piping commands to a shell but keeping interactivity

<d592d8afc5fe21c2cc8b9174c69fd0ce@msgid.frell.theremailer.net>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=14729&group=comp.os.linux.misc#14729

  copy link   Newsgroups: comp.os.linux.misc
From: fritz@spamexpire-202403.rodent.frell.theremailer.net (Fritz Wuehler)
Subject: Re: Piping commands to a shell but keeping interactivity
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
References: <urhjc6enkl@dont-email.me>
<l44pliF6eejU2@mid.individual.net> <urjj7j038r@dont-email.me>
<wwvzfvmi9bp.fsf@LkoBDZeT.terraraq.uk> <l47faiFkqi7U1@mid.individual.net>
<uscpnt4tr1@dont-email.me>
Message-ID: <d592d8afc5fe21c2cc8b9174c69fd0ce@msgid.frell.theremailer.net>
Date: Fri, 08 Mar 2024 05:56:59 +0100
Newsgroups: comp.os.linux.misc
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news.in-chemnitz.de!news2.arglkargh.de!alphared!sewer!news.dizum.net!not-for-mail
Organization: dizum.com - The Internet Problem Provider
X-Abuse: abuse@dizum.com
Injection-Info: sewer.dizum.com - 2001::1/128
 by: Fritz Wuehler - Fri, 8 Mar 2024 04:56 UTC

James Harris <james.harri...@gmail.com> [JH]:
JH> What this is for is code to list files in a folder
JH> which are duplicates of those in another folder
JH> $ ./lsdup.py -r c d

No need to reinvent the wheel:

$ fdupes --recurse c d

fdupes(1) will find duplicate files even with different filenames.

Adding the "--delete" option will prompt user for files to preserve,
deleting all others.

Re: Piping commands to a shell but keeping interactivity

<usfatr$1p25q$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=14824&group=comp.os.linux.misc#14824

  copy link   Newsgroups: comp.os.linux.misc
Path: i2pn2.org!i2pn.org!newsfeed.endofthelinebbs.com!news.hispagatos.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: candycanearter07@candycanearter07.nomail.afraid (candycanearter07)
Newsgroups: comp.os.linux.misc
Subject: Re: Piping commands to a shell but keeping interactivity
Date: Fri, 8 Mar 2024 15:30:04 -0000 (UTC)
Organization: the-candyden-of-code
Lines: 18
Message-ID: <usfatr$1p25q$2@dont-email.me>
References: <urhjc6enkl@dont-email.me> <l44pliF6eejU2@mid.individual.net>
<urjj7j038r@dont-email.me> <wwvzfvmi9bp.fsf@LkoBDZeT.terraraq.uk>
<l47faiFkqi7U1@mid.individual.net> <uscpnt4tr1@dont-email.me>
<d592d8afc5fe21c2cc8b9174c69fd0ce@msgid.frell.theremailer.net>
Injection-Date: Fri, 8 Mar 2024 15:30:04 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ec498b13dc77f8bb37bca0f724f9f673";
logging-data="1870010"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+qwTxk/lRGvmfmq/Rpm526gK4A6d4ks5GM+C0YcXi5IA=="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:2Zyv0EhupuxEWMAQWe6On1tIPsQ=
 by: candycanearter07 - Fri, 8 Mar 2024 15:30 UTC

Fritz Wuehler <fritz@spamexpire-202403.rodent.frell.theremailer.net> wrote at 04:56 this Friday (GMT):
> James Harris <james.harri...@gmail.com> [JH]:
> JH> What this is for is code to list files in a folder
> JH> which are duplicates of those in another folder
> JH> $ ./lsdup.py -r c d
>
> No need to reinvent the wheel:
>
> $ fdupes --recurse c d
>
> fdupes(1) will find duplicate files even with different filenames.
>
> Adding the "--delete" option will prompt user for files to preserve,
> deleting all others.

I never knew about this program, thanks!
--
user <candycane> is generated from /dev/urandom

Re: Piping commands to a shell but keeping interactivity

<usiep7$2g66g$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=14826&group=comp.os.linux.misc#14826

  copy link   Newsgroups: comp.os.linux.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: james.harris.1@gmail.com (James Harris)
Newsgroups: comp.os.linux.misc
Subject: Re: Piping commands to a shell but keeping interactivity
Date: Sat, 9 Mar 2024 19:54:13 +0000
Organization: A noiseless patient Spider
Lines: 49
Message-ID: <usiep7$2g66g$1@dont-email.me>
References: <urhjc6enkl@dont-email.me> <l44pliF6eejU2@mid.individual.net>
<urjj7j038r@dont-email.me> <wwvzfvmi9bp.fsf@LkoBDZeT.terraraq.uk>
<l47faiFkqi7U1@mid.individual.net> <uscpnt4tr1@dont-email.me>
<d592d8afc5fe21c2cc8b9174c69fd0ce@msgid.frell.theremailer.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 9 Mar 2024 19:54:15 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="925872533883db4b378940619306b515";
logging-data="2627792"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18BcAz7SdYunDfIyokATILMFlZH+Xge2To="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:kHpKpFGeZ5c9xoGrXGMCrgMjqV0=
In-Reply-To: <d592d8afc5fe21c2cc8b9174c69fd0ce@msgid.frell.theremailer.net>
Content-Language: en-GB
 by: James Harris - Sat, 9 Mar 2024 19:54 UTC

On 08/03/2024 04:56, Fritz Wuehler wrote:
> James Harris <james.harri...@gmail.com> [JH]:
> JH> What this is for is code to list files in a folder
> JH> which are duplicates of those in another folder
> JH> $ ./lsdup.py -r c d
>
> No need to reinvent the wheel:
>
> $ fdupes --recurse c d
>
> fdupes(1) will find duplicate files even with different filenames.

Different use case. fdupes reports duplicates anywhere, even in the same
'master' folder. By contrast,

$ ./lsdup.py -h
Usage:

./lsdup.py [opt...] master candidate...

Lists files etc in the candidate folders which are duplicates of
those in the master folder.

By default, this program will report those files which match on all of
eight attributes: name, size, UID, GID, disposition, permissions,
modification time, and content but can be told to ignore certain
mismatches (and thus list those files as duplicates).

For example, you may wish to identify a file as a duplicate even if
it has a different UID and GID as long as all other attributes match.

A file's name and its position in the folder hierarchy must always
match, and both must be regular files (not named pipes, for example).

etc.

>
> Adding the "--delete" option will prompt user for files to preserve,
> deleting all others.

I have tried it but it required too much manual intervention.

--
James Harris

Re: Piping commands to a shell but keeping interactivity

<usiidu$2gve6$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=14827&group=comp.os.linux.misc#14827

  copy link   Newsgroups: comp.os.linux.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: james.harris.1@gmail.com (James Harris)
Newsgroups: comp.os.linux.misc
Subject: Re: Piping commands to a shell but keeping interactivity
Date: Sat, 9 Mar 2024 20:56:28 +0000
Organization: A noiseless patient Spider
Lines: 150
Message-ID: <usiidu$2gve6$1@dont-email.me>
References: <urhjc6$2enkl$1@dont-email.me> <l44pliF6eejU2@mid.individual.net>
<urjj7j$3038r$1@dont-email.me> <wwvzfvmi9bp.fsf@LkoBDZeT.terraraq.uk>
<l47faiFkqi7U1@mid.individual.net> <uscpnt$14tr1$1@dont-email.me>
<use1ac$1gd9k$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 9 Mar 2024 20:56:30 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="925872533883db4b378940619306b515";
logging-data="2653638"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18dKYW9R2N8LJCjr1hxMz4V5bdsUP+G3Bw="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:RKNLgIo0xeU/I0oYN5znM8cKv/0=
In-Reply-To: <use1ac$1gd9k$1@dont-email.me>
Content-Language: en-GB
 by: James Harris - Sat, 9 Mar 2024 20:56 UTC

On 08/03/2024 03:39, Rich wrote:
> James Harris <james.harris.1@gmail.com> wrote:
>> That's right. What this is for is code to list files in a folder
>> which are duplicates of those in another folder (same name, same
>> relative place in the folder hierarchy, etc). For example, say there
>> are two folders, c and d, and one is potentially a copy of the other.
>> The command
>>
>> $ ./lsdup.py -r c d
>>
>> lists files in d (and subdirectories due to the -r recurse option) which
>> are duplicates of those in c.
>>
>> In answer to your other point about using xargs, I would use it if it
>> would do what's required, and do so consistently,
>
> It will, provided you output file names with ASCII null terminators
> instead of ASCII newlines, and use the -0 option to tell xargs the
> filenames are null separated.
>
>> but I am not sure whether I can trust it or not.
>
> You can. Provided you feed it ASCII null terminated filenames, it will
> work properly, no matter what other weird characters might be in the
> filenames.

You are right: unusual characters in file names is the kind of issue I
am wary about with xargs. Running a command to do automatic deletion
requires a lot of trust in the command's operation.

I /have/ been thinking about adding a -0 option but it has issues such as:

(1) With -0 one cannot easily postprocess the list of file names, if
required.

(2) With xargs interactivity (e.g. the -i in rm -i) is lost.

Yes, there are ways round such issues but they may require altering a
command line /after/ it has been found to be correct. That was the issue
which led to this thread. If I I generate a list of delete commands with
a series of commands such as

A | B

then once I am happy with them I would prefer simply to append | sh as in

A | B | sh

rather than changing the form to

sh <(A | B)

This is not so much about convenience as about making sure less can go
wrong - always a good idea when deleting files by means of a command.

IMO better than a -print- or -0 option would be a function which would
render file names exactly as the current shell would - same escape
sequences, etc.

....

>> (A separate command, lsempty.py, is is used to delete the resultant
>> empty folders.)
>
> A separate python command is completely unnecessary. Removing empty
> leaf directories is already easy using the tools provided by the
> system.:
>
> $ find c d -type d -empty -print0 | xargs -0 rmdir
>
> If you also want to remove parent empty directories should all their
> children go away, change to:
>
> $ find c d -type d -empty -print0 | xargs -0 rmdir -p

Thanks. That looks as though it would work, albeit that it would print a
few spurious error messages which add to the work of the person running
the code. For example,

$ find f -type d -empty -print0 | xargs -0 rmdir -pv
rmdir: removing directory, 'f/1/2/3'
rmdir: removing directory, 'f/1/2'
rmdir: removing directory, 'f/1'
rmdir: failed to remove directory 'f/1': Directory not empty
rmdir: removing directory, 'f/b/c/d'
rmdir: removing directory, 'f/b/c'
rmdir: removing directory, 'f/b'
rmdir: failed to remove directory 'f/b': Directory not empty
rmdir: removing directory, 'f/b/g/h'
rmdir: removing directory, 'f/b/g'
rmdir: removing directory, 'f/b'
rmdir: failed to remove directory 'f/b': Directory not empty
$

Note, in particular, the repetitions of f/b.

By contrast, my version of the above is clearer:

$ ./lsempty.py f | sed 's/^/rmdir -v /' | sh
rmdir: removing directory, 'f/1/2/3'
rmdir: removing directory, 'f/1/2'
rmdir: removing directory, 'f/b/c/d'
rmdir: removing directory, 'f/b/c'
rmdir: removing directory, 'f/b/g/h'
rmdir: removing directory, 'f/b/g'
$

>
>> In answer to the point about filenames with spaces and odd characters, I
>> currently output names in single quotes, as above. This will
>> complain until the parent is empty, but the complaints can be
>> ignored.
>
> Single quote is also a possible filename character, so if, by chance,
> you end up with a file containing one ' somewhere your wrapping in
> single quotes will result in a fail at that point.

I deal with that (at present) by juxtaposing single-quoted strings. For
example, if there is a file called

won't scan.txt

with an apostrophe and a space then I get the following results. First,
the command:

$ ./lsdup.py c d -r | grep won | sed 's/^/rm -v /'
rm -v 'd/won'\''t scan.txt'

Then, piping that command to the shell works properly in:

$ ./lsdup.py c d -r | grep won | sed 's/^/rm -v /' | sh
removed "d/won't scan.txt"

IOW the file name becomes the concatenation of

'won'
\'
't scan.txt'

That said, I am not sure that this will work in all cases and expect
that a function to render a file name to match the current shell would
be more dependable. Pity that shells don't provide such a function ...
AFAIK.

--
James Harris

Re: Piping commands to a shell but keeping interactivity

<usim9j$2hqge$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=14828&group=comp.os.linux.misc#14828

  copy link   Newsgroups: comp.os.linux.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: rich@example.invalid (Rich)
Newsgroups: comp.os.linux.misc
Subject: Re: Piping commands to a shell but keeping interactivity
Date: Sat, 9 Mar 2024 22:02:28 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 164
Message-ID: <usim9j$2hqge$1@dont-email.me>
References: <urhjc6$2enkl$1@dont-email.me> <l44pliF6eejU2@mid.individual.net> <urjj7j$3038r$1@dont-email.me> <wwvzfvmi9bp.fsf@LkoBDZeT.terraraq.uk> <l47faiFkqi7U1@mid.individual.net> <uscpnt$14tr1$1@dont-email.me> <use1ac$1gd9k$1@dont-email.me> <usiidu$2gve6$1@dont-email.me>
Injection-Date: Sat, 9 Mar 2024 22:02:28 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="1d95848d99d0a249e466461ccd04331e";
logging-data="2681358"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/EcQtSL2JBFowNnQG4mTDy"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:eeDVTpXIl+5ypOtC3T2Hf0tYCLE=
 by: Rich - Sat, 9 Mar 2024 22:02 UTC

James Harris <james.harris.1@gmail.com> wrote:
> On 08/03/2024 03:39, Rich wrote:
>> James Harris <james.harris.1@gmail.com> wrote:
>>> That's right. What this is for is code to list files in a folder
>>> which are duplicates of those in another folder (same name, same
>>> relative place in the folder hierarchy, etc). For example, say there
>>> are two folders, c and d, and one is potentially a copy of the other.
>>> The command
>>>
>>> $ ./lsdup.py -r c d
>>>
>>> lists files in d (and subdirectories due to the -r recurse option) which
>>> are duplicates of those in c.
>>>
>>> In answer to your other point about using xargs, I would use it if it
>>> would do what's required, and do so consistently,
>>
>> It will, provided you output file names with ASCII null terminators
>> instead of ASCII newlines, and use the -0 option to tell xargs the
>> filenames are null separated.
>>
>>> but I am not sure whether I can trust it or not.
>>
>> You can. Provided you feed it ASCII null terminated filenames, it will
>> work properly, no matter what other weird characters might be in the
>> filenames.
>
> You are right: unusual characters in file names is the kind of issue I
> am wary about with xargs.

And this is exactly why xargs was modified to consume null terminated
names, so that no otherwise legal filename character would create a
problem. And ASCII newline is also a legal filename character.

> Running a command to do automatic deletion requires a lot of trust in
> the command's operation.

Agreed.

> I /have/ been thinking about adding a -0 option but it has issues such as:
>
> (1) With -0 one cannot easily postprocess the list of file names, if
> required.

That depends upon what you mean by 'postprocessing'.

GNU sort has -z, --zero-terminated options to inform it to process
"lines" with ASCII null terminators.

GNU grep has -z, --null-data options to also inform it to process
"lines" that are ASCII null terminated.

If you want to "preview" in something like less, you can add
"tr '\0' '\n'" to the pipeline before less to conver the nulls into
newlines so that any filename other than one with an actual newline in
it would be one line in less.

> (2) With xargs interactivity (e.g. the -i in rm -i) is lost.

This is true, so if you value using -i to acknowledge each file
individually then yes, using xargs to launch rm is not in the cards.

Although a small workaround would be to use xargs (GNU xargs at least)
option -p, --interactive combined with -n 1 to run one rm per filename
and have xargs prompt (instead of rm) before each. This loses the
efficiency gains of one rm and a maximum number of filenames, but it
does allow 'interactivity' again.

> Yes, there are ways round such issues but they may require altering a
> command line /after/ it has been found to be correct. That was the issue
> which led to this thread. If I I generate a list of delete commands with
> a series of commands such as
>
> A | B
>
> then once I am happy with them I would prefer simply to append | sh as in
>
> A | B | sh
>
> rather than changing the form to
>
> sh <(A | B)

With xargs and nulls, the change becomes:

A | B | tr '\0' '\n' | less
to
A | B | xargs -0 rm
or
A | B | xargs -0 -n 1 -p rm (for interactive deletes)

> This is not so much about convenience as about making sure less can go
> wrong - always a good idea when deleting files by means of a command.

Yes, if you have no backup with which to recover then agreed, verifying
the deletion before deleting is important.

>>> (A separate command, lsempty.py, is is used to delete the resultant
>>> empty folders.)
>>
>> A separate python command is completely unnecessary. Removing empty
>> leaf directories is already easy using the tools provided by the
>> system.:
>>
>> $ find c d -type d -empty -print0 | xargs -0 rmdir
>>
>> If you also want to remove parent empty directories should all their
>> children go away, change to:
>>
>> $ find c d -type d -empty -print0 | xargs -0 rmdir -p
>
> Thanks. That looks as though it would work, albeit that it would print a
> few spurious error messages which add to the work of the person running
> the code. For example,

If you dislike the spurious erros, then add the --ignore-fail-on-non-empty
option, which suppresses the errors for 'not empty' as rmdir walks back
up the tree.

>>> In answer to the point about filenames with spaces and odd
>>> characters, I currently output names in single quotes, as above.
>>> This will complain until the parent is empty, but the complaints
>>> can be ignored.
>>
>> Single quote is also a possible filename character, so if, by
>> chance, you end up with a file containing one ' somewhere your
>> wrapping in single quotes will result in a fail at that point.
>
> I deal with that (at present) by juxtaposing single-quoted strings.
> For example, if there is a file called
>
> won't scan.txt
>
> with an apostrophe and a space then I get the following results. First,
> the command:
>
> $ ./lsdup.py c d -r | grep won | sed 's/^/rm -v /'
> rm -v 'd/won'\''t scan.txt'

Ok, you had not yet revealed you were doing so, and we can't read your
mind remotely over Usenet to know you are handling single quotes
properly (at least for one single quote in a filename).

> That said, I am not sure that this will work in all cases and expect

Provided you replace every input instance of ' with '\'' it would work
(at least for ').

The minefield aspect into which you are traversing is that each shell
has a different set of meta-characters that are 'special' to it and so
the proper "escaping" is dependent upon /which/ shell the output is
being piped into.

And by piping into the shell, if your escaping is not 100% perfect, you
open yourself up to someone crafting a filename that results in your
shell doing one of:

"rm -fr /"

or

"rm -fr ~"

depending upon whether you run the deletion as root or a non-root user.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor