The zathura man page states

zathura displays the given files. If a single hyphen-minus (-) is given as file name, the content will be read from standard input. If no files are given, an empty zathura instance launches.

Indeed, this works in bash if I run the command cat document.pdf | zathura -. However, I am unable to generalize this to other cases. Specifically, if I create a folder containing only document.pdf, running the command ls | zathura - returns an error, saying that zathura could not determine the file type. Why is this? Am I misunderstanding how piping works?

1 Answer 1

cat document.pdf | zathura -

Pipes the content of document.pdf to Zathura, which tries to render it.

ls | zathura -

If you have only document.pdf directory and nothing else, that pipes the string document.pdf to Zathura, not its contents, so Zathura complains. Moreover, if you try to write a program and it involves parsing ls, you are most probably doing it wrong.

  • I see, thank you for the explanation. Is there any way to get around this? I agree that generally parsing ls is not ideal. However, the specific task I was trying to accomplish was to open the most recent file in a directory with zathura. All the files are generated by myself and I have no intent of ever adding anything weird, like newlines, into the file name. Accessing this file (or I guess more precisely, the string) can be done with ls -Art | tail -n 1, but piping this into zathura gives the same error for the reason you described. Commented May 6, 2020 at 22:18
  • @HenryShackleton You're welcome. In that special case, I think you issue cat "$(ls -Art | tail -n 1)"|zathura -. Although I never used Zathura, I guess that would be equivalent to zathura "$(ls -Art | tail -n 1)". However, in case you want to do something robust, something with find -exec would be good.
    – Quasímodo
    Commented May 6, 2020 at 22:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .