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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading from a pipe

Status
Not open for further replies.

gsopitan

MIS
Oct 14, 2008
5
US
I wrote a command that performs a series of function. The command works this way

Case1: commandname option value
$0 $1 $2

It should also works this way

case 2: value | commandname option

In case 1, I refer to "value" in my script using parameter $2. I am not sure how to read or what parameter to use to refer to "value" when it's coming from a pipe. Any help will be appreciated.

Thanks

 
I case 2, value needs to be a command... are you aware of that?

Something like this perhaps:

Code:
# if only one parameter has been supplied
if [[ $# -eq 1 ]]
then
    # read value from standard input
    read VALUE
else
    # value is second parameter
    VALUE=$2
fi

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top