0

The (bash) command find . -name "documentation.html" | xargs xdg-open finds a file and passes its path to xdg-open, but xdg-open errors out:

xdg-open: unexpected argument './distribution/docs/target/docs/html/documentation.html'

The command find . -name "documentation.html" -exec xdg-open {} + results in the same error

Why? Is find passing the quote character to xdg-open? I can't figure it out.

1

This might be caused by extra characters piped into xargs or errors (i.e. permission denied for certain dirs).

If you want to pass only one file to xargs you can try this:

find -type f -name "documentation.html" 2> /dev/null | head -n 1 | xargs -n 1 xdg-open

or

xdg-open `find -type f -name "examples.desktop" 2> /dev/null`

Another solution will be while loop:

find -type f -name "examples.desktop" 2> /dev/null | while read -r FILE ; do xdg-open "$FILE" ; done
| improve this answer | |
  • So xdg-open is interpreting the argument as a .... list? – ahoffer May 8 '19 at 15:32
  • yes, read about it here: pl.wikipedia.org/wiki/Xargs – Comar May 8 '19 at 15:33
  • Oddly "find . -name "documentation.html" | xargs xdg-open" just starting doing what I would expect it to do -- open the file "documentation.html" in a web browser. I have no idea why it suddenly started working. – ahoffer May 8 '19 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.