0

I have written a command that will search Credhub to find entries that match a certain condition and then delete those matching items. It works perfectly. Problem is that I want this command to not do anything if it doesn't find any matches.

Here is what I have

credhub find -n sachin | grep name: | cut -c9- | xargs -I {} credhub delete -n {}

How can I change this to do nothing if no matches are found?

Sachin Kainth
  • 45,256
  • 81
  • 201
  • 304
  • 5
    GNU `xargs` has a `-r` option – Fravadona Jul 13 '22 at 10:49
  • 2
    @Fravadona: Perhaps this would be worth to make an answer rather than a comment. The `-r` is an often underrated option of xargs. – user1934428 Jul 13 '22 at 10:57
  • 2
    Does this answer your question? [How to ignore xargs commands if stdin input is empty?](https://stackoverflow.com/questions/8296710/how-to-ignore-xargs-commands-if-stdin-input-is-empty) – pjh Jul 13 '22 at 18:11

0 Answers0