my script should be run through a pipe like this:
echo "hello" | mysript.sh
I read the input with input=cat
However if it's run without a pipe cat waits for input - how can I fix this?
There is nothing to fix as it sounds like it works like every other utility that accepts input via stdin
. That's a good thing.
tar
, for instance, will exit with an error if run without an input file and with stdin pointed to a TTY in creation mode.
May 31, 2016 at 15:57
tar cf - . | (cd /path; tar xfv -)
should work fine.
May 31, 2016 at 16:00
myscript <in.txt
is surely intended to proceed without error, whether in.txt
is a regular file, a named FIFO, &c.
May 31, 2016 at 16:06
^D
when done.myscript <hello.txt
not to abort, right?