Operating System - HP-UX
1833154 Members
3049 Online
110051 Solutions
New Discussion

piping commands to a process in a script question and problem

 
Doug_3
Frequent Advisor

piping commands to a process in a script question and problem

Hi all,
I am confused by several methods of piping commands w/in a script. I also have a problem getting a script to work.

I have seen the following:

yes | command params

block of code:
command params << !
^M
!

And this one (even I understand):
command | command | command

Any explanatory comments on the use of each method?

Also....I am trying to get a script to execute as an mpe command. Normally from the command line you would type:
#mpe
:command
:bye
#(back to ksh)

The command is actually two commands seperated by a semicolon. fence 7;queue=myjobque
I believe the shell is interpeting the semicolon. I need to pipe the command to the mpe shell as one string.

I have tried:
"string1;string2" | mpe
string1;string2 | mpe
mpe < string1;string2

Ideas?

tia
Doug
2 REPLIES 2
A. Clay Stephenson
Acclaimed Contributor

Re: piping commands to a process in a script question and problem

Your first example is called a 'here document'. It means that anything up to an ending string is treated just as though you typed it in at the keyboard.
e.g.
cat << !EOF! > myfile
This is a test
This is some more stuff
!EOF!

cat myfile

would instruct cat to read from stdin and load lines until it sees '!EOF!'. At that point normal shell interpretation resumes and the next command is 'cat myfile'.

----------------------

I think what you are looking for is a 'compound command'.
( cmd1; cmd2; cmd3 ) | cmd4

This will take the stdouts of cmd1, cmd2, cmd3 (executed in that order) and feed them to stdin of cmd4.
If it ain't broke, I can fix that.
Christian Gebhardt
Honored Contributor

Re: piping commands to a process in a script question and problem

Try this

#!/bin/sh
mpe <:command
:bye
EOFMPE

This means that :command and :bye are commands given to mpe

EOFMPE is a arbitrary string, the second EOFMPE have to be placed completely in front of the line

Chris