xargs and gnuplot

Hi All,

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.

Any ideas would be greatly appreciated.

Thanks in advance.

Unless you have enough .dat files to get "Argument list too long":

myscript.sh *.dat

Maybe ls ...| xargs ... is not needed, but if that's the case, then try:

printf "%s\n" file*.dat | xargs -n1 -p myscript.sh

Also the pause -1 records might need to be removed from the gnuplot command file.

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)?!?!?:confused:

---------- 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.

Does your script read filenames from stdin? If not, you can't use a pipe like that.

myscript.sh $( cut -f2 masterlist )

---------- Post updated at 07:52 PM ---------- Previous update was at 07:48 PM ----------

If you are waiting for input, calling gnuplot repeatedly will not make much difference. (Though generally I would agree with you.)

Bingo! Thanks so much cfajohnson! That does what I need.

I have not seen that $( cut -f2 masterlist ) syntax before.

Any suggestions for keyword(s) I can search on to learn more about the '$(...)' ?

Thanks again!

Read the Command Substitution section of your shell's man page.

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.

Agreed, but the problem was originally stated differently [*].

[*]

[-]

This is a totally new element in the equation.

Glad you found a solution.

Sorry, tried my best to explain. I thought the

would have done the trick. Probably would have been helpful if I had mad the file contents example look like one individual file, maybe like

-----file begin-----
gnuplot commands for first .dat file
pause -1

gnuplot commands for second .dat file
pause -1

etc,etc,etc
-----file end-----

---------- Post updated at 08:15 PM ---------- Previous update was at 08:06 PM ----------

Oh boy...now I am getting confused again. Don't

ls file*.dat | myscript.sh

and

cut -f2 masterlist | myscript.sh 

both just give me a list of "stuff" that is piped to myscript.sh? What is new about using cut vs. ls?