bugfindutils - Bugs: bug #62268, [feature request] -quit N to make...

 
 

bug #62268: [feature request] -quit N to make find exit immediately with a certain exit code

Submitter:  Martin von Wittich <martinvonwittich>
Submitted:  Fri 08 Apr 2022 01:45:11 PM UTC
   
 
Category:  find Severity:  3 - Normal
Item Group:  None Status:  None
Privacy:  Public Assigned to:  None
Originator Name:  Open/Closed:  Open
Release:  None Fixed Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 08 Apr 2022 02:57:14 PM UTC, comment #1: 

NetBSD find supports this as -exit [N] (https://man.netbsd.org/find.1)

The difference with -quit is that -exit suppresses the default -print, which is often what you want if you're just checking the exit code.

Tavian Barnes <tavianator>
Fri 08 Apr 2022 01:45:11 PM UTC, original submission:  

A very typical use case for find in shell scripting is to check if some files exist, e.g. in an if block:


if find /tmp -name 'some_pattern*' | grep -q .
then
  do_something
fi


Unfortunately find currently doesn't have any way to communicate "some matches" or "no matches" via exit code, necessitating the grep -q workaround, or another workaround like -exec false:


if find /tmp -name 'some_pattern*' -exec false {} +
then
  do_something
fi


There is a -quit operator that exits find immediately, but it doesn't currently support specifying an exit code. It would be useful if it were possible to specify an exit code via -quit N so we could use find like this:


if ! find /tmp -name 'some_pattern*' -quit 1
then
  do_something
fi


Adding support for specifying an exit code has been suggested by berny before, but unfortunately it went unnoticed: https://savannah.gnu.org/bugs/?func=detailitem&item_id=54730#comment6


Martin von Wittich <martinvonwittich>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by tavianator (Posted a comment)
  • -email is unavailable- added by martinvonwittich (Submitted the item)
  • -email is unavailable- added by martinvonwittich
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-04-08 martinvonwittich Carbon-Copy- Added berny

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code