I'm looking for an elegant cross-compatible way to direct the names of files into
entr. I know the following works with Bash, but I'd like a command that would work in other shells.
entr is a program that watches files and runs a command on start and when those files change. Its documentation shows
ls *.ext, for example, piped into it - so it is expecting a newline separated list of legitimate filenames piped to it. It warns on bad filenames.)
This command lets me list specific files with a multiline herestring:
$ entr echo "command ran" <<< " > filename1 > filename2 > "
I find the quotation marks and having to list them on separate lines to be annoying. Also a quick search indicates it might not work in shells other than Bash.
I could use interactive
$ cat | entr echo "command ran" filename2 filename2
but again I have to do a newline each time, not much margin for error, and carefully enter Ctrl-D at the end.
A heredoc works similarly but involves bookend syntax.
$ cat << EOF | entr echo "command ran" > filename1 > filename2 > EOF
I could also do
ls, which looks nice at first glance:
$ ls filename1 filename2 | entr echo "command ran"
ls would strip out misspelled names, while
entr validates and warns on improper names, and I'm worried about side-effects of calling ls in this way.
echo and pipe to
tr before piping to
$ echo filename1 filename2 | tr " " "\n" | entr echo "command ran"
But I don't like having all the extra commands.
How do I write a short, elegant command that works in most (preferably all) shells? Syntax expected by posix would be ideal.