1

I have a shell script that I want to use to pass options into the pdf reader zathura. It outputs something like:

filename.pdf -P 5 -f "some search phrase"

The -P option gives a page number to open the pdf at and -f gives a searchterm to be highlighted. If I simply run

zathura filename.pdf -P 5 -f "some search phrase"

this works perfectly fine. It opens filename.pdf on page 5 and highlights the string some search phrase. However if I invoke the script that gives me these options via a subshell like this:

zathura $(myscript)

It seems to interpret search and phrase" as separate files. So three zathura windows open, one with the pdf opened on the correct page, but the search string being "some instead of some search phrase and then two more windows where the file can understandably not be found. It tries to open search and phrase" as files here. If I modify the script so that there are no double quotes around the argument of -f and search for a string that does not have spaces, it works as expected. However, I need to be able to search for phrases that have spaces in them.

I have tried all sort of things to solve this, but I am at the end of my tether at this point. The result of the command substitution is certainly correct and the behaviour can be replicated if I simply do:

zathura $(echo "filename.pdf -P 5 -f \"some search phrase\"")

List of things I tried:

  • I escaped the double quotes with backslashes
  • I exchanged the double quotes with single quotes, precisely the same problem persists
  • I tried it in zsh instead of bash
  • I escaped the spaces with backslashes
  • I put double quotes around the command substitution, which obviously results in all options being interpreted as files
  • I put the options before the filename
  • I changed the order of the options around
  • Combined several of the aforementioned

I have tried to read up on it online, but to no avail. If someone could help me with this and explain what is going on I would most appreciate it.

smarkjk
  • 11
  • 1

0 Answers0