Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you tell the name of a file in a pipeline ?

Status
Not open for further replies.

JohnLynn

Technical User
Feb 2, 2001
38
US
If you pipe one command to a shell script:
cat test.file | MY_PRINTFILTER.SH

How do you tell the name of the file being piped to you?

I understand that in "MY_PRINTFILTER.SH test.file" this is $1.

Thanks
John

 
At a guess, if your "cat" a file and then pipe it to a script, then you're not really passing a file (in the true sense) ... you're piping STDOUT to the script.

Greg.
 
I agree with Greg.

You can do something like that.
Code:
cat test.file | PIPESRCFILE=test.file MY_PRINTFILTER.SH

Then in your script:
Code:
inputfile=${PIPESRCFILE:-$1}

This way
Code:
$inputfile
is
Code:
$PIPESRCFILE
if that variable exists, else it is
Code:
$1
so that you can still use
Code:
MY_PRINTFILTER.SH test.file
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top