Seems I have an xargs stdin problem that I don't understand.
I have a script (call it myscript.sh) that takes the names of one or more file(s) specified on the command line and creates a single gnuplot command file containing multiple records, one for each specified file. Each of those records is terminated by a gnuplot "pause -1" command that suspends execution until the user presses the enter key. Sort of like this:
gnuplot commands for first .dat file
pause -1
gnuplot commands for second .dat file
pause -1
etc,etc,etc
If I run 'myscript.sh file1.dat file2.dat', it works as expected and gnuplot waits for me to press the enter key before moving onto the next plot.
But, if I do something like 'ls file*.dat | xargs myscript.sh' gnuplot runs through all of the plots without waiting for me to press enter.
So, gnuplot is getting something from stdin effectively making my pause commands useless.
Thanks for the reply cfajohnson. Your suggestion is ok for trivial cases (and I use it this way for those cases). I am having trouble with things like:
cut -f2 masterlist | myscript.sh
Other suggestions? I guess I am trying to find a way to get stdin back from the pipe and reopen it to the keyboard (or something like that)?!?!?
---------- Post updated at 06:46 PM ---------- Previous update was at 06:40 PM ----------
Thanks rubin. Unfortunately, the most efficient way to use gnuplot in this instance is to build one command file for all specified files and then pass that one command file to gnuplot. Doing them one by one with the "-n1 -p" options won't help me in this case.
Sweet! Thanks again. I don't write scripts often (obvious, huh?). I know many years ago I read various shell manuals from end-to-end but seems I have only needed I/O redirection for most (all) stuff in recent years. Completely forgot about command substitution. Now that I think about it, I feel (am) stupid for having to ask.