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.)
multiliners
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
:
$ 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
one-liners:
I could also do ls
, which looks nice at first glance:
$ ls filename1 filename2 | entr echo "command ran"
But 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.
I could echo
and pipe to tr
before piping to entr
:
$ echo filename1 filename2 | tr " " "\n" | entr echo "command ran"
But I don't like having all the extra commands.
The Question:
How do I write a short, elegant command that works in most (preferably all) shells? Syntax expected by posix would be ideal.
frobnicate 'echo "command ran"' filename1 filename2
orfrobnicate filename1 filename2
(andecho "command ran"
is fixed) or "I'd like to pick files from the current directory interactively". For now we know few syntaxes you don't like. What would you like?printf "%s\n" filename1 "filename with spaces 2" | entr echo "command ran"