3

I am attempting to use the 'entr' command to automatically compile Groff documents.

I wish to run the following line:

refer references.bib $1 | groff -ms $1 -T pdf > $2

Sadly it will only compile once if I try this:

echo $1 | entr refer references.bib $1 | groff -ms $1 -T pdf > $2

I have also tried the following, but it creates an infinite loop that cant be exited with Ctrl+C:

compile(){
    refer references.bib $1 | groff -ms $1 -T pdf > $2
}

while true; do
    compile $1 $2
    echo $1 | entr -pd -s 'kill $PPID'
done

What is the correct way of doing this?

AEM
  • 1,354
  • 8
  • 20
  • 30
Eidolon
  • 309
  • 3
  • 12
  • For reference: https://github.com/eradman/entr – Eidolon Jun 02 '21 at 15:47
  • Code which doesn't do what you want is a poor way to describe what you do want. What do you hope these commands should do? – tripleee Jun 02 '21 at 15:56
  • I wish to automatically generate references and compile the Groff document when changes are made to the document. – Eidolon Jun 02 '21 at 16:01
  • The first command listed is how I would compile and generate references; I wish to use entr to automatically run that. – Eidolon Jun 02 '21 at 16:03
  • Thanks. Probably [edit] more details into the question itself; comments are likely to be deleted after a while. – tripleee Jun 02 '21 at 16:03

1 Answers1

4

I didn't try this because I didn't want to install entr. But I think the following should work:

echo "$1" | entr sh -c "refer references.bib $1 | groff -ms $1 -T pdf > $2"

Note that we run the pipe refer | groff in a shell to group it together. The command from your question without the shell runs refer upon file change, but groff only once. In entr ... | groff the groff part isn't executed by entr, but by bash in parallel.

This command works only if $1 and $2 do not contain special symbols like spaces, *, or $. The correct way to handle these arguments would be ...

echo "$1" | entr sh -c 'refer references.bib "$1" | groff -ms "$1" -T pdf > "$2"' . "$1" "$2"
Socowi
  • 25,550
  • 3
  • 32
  • 54
  • @Eidolon Yes, I think `entr` interpreted the whole script as a command name. I edited the answer. Can you try again? – Socowi Jun 02 '21 at 17:32