- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Help with standard input to a script.
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-05-2002 03:42 AM
тАО03-05-2002 03:42 AM
Help with standard input to a script.
I have a requirement for a script that can handle a file that is piped in via standard input.
i.e cat inputfile | my_script
Once inside the script how can I reference the inputfile?
With normal inputs you can use $1 $2 etc, is there anything like that for piped input??
Cheers
Russ.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-05-2002 10:50 AM
тАО03-05-2002 10:50 AM
Re: Help with standard input to a script.
while read X |
do
echo $X
# reads stdin 1 line at a time
done
If you would like split each line into $1, $2, ...
ARGS=$*
while read X |
do
set $X
# now $X has been split into $1, $2, ...
# $# is the number of vars
done
No points please, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-05-2002 11:39 AM
тАО03-05-2002 11:39 AM
Re: Help with standard input to a script.
I would use an exported variable, which can then be read within your script:
FILE=inputfile
export FILE
cat $FILE | your_script
Rgds, Robin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-05-2002 06:15 PM
тАО03-05-2002 06:15 PM
Re: Help with standard input to a script.
while read w1 w2 w3 w4 w5 w6 w7 w8 w9 w10
do
echo $w1 $w2 $w3 $w4 $w5 $w6 $w7 $w8 $w9 $w10
done
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-05-2002 06:28 PM
тАО03-05-2002 06:28 PM
Re: Help with standard input to a script.
I agree with Robin.
Had wanted to post exactly the same yesterday but was unable to due to forum connectivity issues with replying.
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-05-2002 11:14 PM
тАО03-05-2002 11:14 PM
Re: Help with standard input to a script.
why don't you simply change positions using command substitution:
your_script `cat input_file`
you use the standard input for the input file and you get a parameter list which you can use inside your script...
Allways stay on the bright side of life!
Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-05-2002 11:48 PM
тАО03-05-2002 11:48 PM
Re: Help with standard input to a script.
# your_script inputfile
In your_script, you can add these lines:
while read field1 field2 field3
do
your_process
done < $1
This will read the lines from your inputfile and do the process that you want. If you inputfile had 7 fields, add up to field7 in the 'while' line.
Hope this helps.
Kenny.