[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug #61009] xargs need option to immediately stop on command fail

From: Bernhard Voelker
Subject: [bug #61009] xargs need option to immediately stop on command fail
Date: Wed, 4 Aug 2021 19:04:00 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:90.0) Gecko/20100101 Firefox/90.0

Update of bug #61009 (project findutils):

             Assigned to:                    None => berny                  


Follow-up Comment #1:

I have to confess that I like the idea of having an option to immediately stop
when an invocation of the command exits with a non-Zero status.

POSIX [1] specifies the following conditions when xargs shall terminate
* child exits with 255,
* child was killed by a signal, or
* when reading the 'eofstr' string if the '-E eofstr' option is given, or
* when regularly reaching EOF when reading from stdin.
Still, our xargs might implement such an option as a GNU extension.
I would recommend a long-option like --stop-on-error for such an extension.
Why did you propose '-F'?  Is there any precedence in other xargs

[1] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/xargs.html

Regarding the examples - and just to be sure:
I assume that the reproducer with 'cp' was just a simplification to
your actual use case, right?  This is my guess because the shown use of
is quite excessive (one cp(1) invocation per file) and unsafe (unusual
would break the construct).
In such a case - when launching one process per file is required -, I'd maybe
better use the `find -exec ... '{}' \;' syntax without xargs, which could also
used in conjunction with -quit to terminate the processing when 'cp' fails:

# Create source and destination directory.
$ mkdir src dst

# Create a regular file 'dst/f' which will cause 'cp' to fail later.
$ touch dst/f

# Create test sub-directories 'a' .. 'g', and a file 'x' in each of them.
$ cd src
$ mkdir a b c d e f g
$ touch a/x b/x c/x d/x e/x f/x g/x

# Run find to copy all files to 'dst', but stopping if 'cp' hits an error.
# Note the use of the '(' ... ')' to enforce the wanted OR-precedence for
# when cp(1) fails.
$ find . -type f '(' -exec cp -fv '{}' '../dst/{}' \; -o -quit ')'
'./b/x' -> '../dst/./b/x'
cp: cannot create regular file '../dst/./b/x': No such file or directory

# Alternatively, avoid the OR-syntax with -not before -exec:
$ find . -type f -not -exec cp -fv '{}' '../dst/{}' \; -quit


Reply to this item at:


  Message sent via Savannah

reply via email to

[Prev in Thread] Current Thread [Next in Thread]