- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Shell script pipe (STDIN/STDOUT/STDERR)
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
Forums
Discussions
Discussions
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
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
08-20-2002 11:12 PM
08-20-2002 11:12 PM
Let's say I've made a (ksh) script named: "ShowPipes.sh" and run the script in the 3 following ways:
$ echo "This is a test" | ./ShowPipes.sh -f /tmp/pipes.txt
$ ./ShowPipes.sh -f /tmp/pipes.txt
$ ./ShowPipes.sh
How do I test within the script if the first case is true - and catch the piped test "This is a test"?
The last 2 way I know, but the problem is, when fx. catching the left input by
LeftInput=`cat`
it hangs, if there is nothing, so I have to get a way how to "kill" that part, if nothing comes in - and "how do we do that"???
PS. And let me just say, I have made a "few" scripts, and as fare as I can see, there is no "simple" way - or...
Kind Regards
Bjarne Dein System Administrator - Unix
Scandinavian IT Group A/S Direct: +45 3232 4610 Mobile: +45 2322 4610 mailto:Bjarne.Dein@SAS.dk
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2002 11:34 PM
08-20-2002 11:34 PM
Re: Shell script pipe (STDIN/STDOUT/STDERR)
I think that you want to check the number of parameters received, isn't?
If yes you can do by checking the shell variable $# this tell you how many parameters received, there are other shell variables interesting like that:
$* all the parameters
$1 the first parameter
$2 the second parameter
shift command skip to the next parameter
Hope this help you,
Justo.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2002 11:37 PM
08-20-2002 11:37 PM
Re: Shell script pipe (STDIN/STDOUT/STDERR)
You can put your script here and I try to help you better.
Welcome to the forum.
Regards,
Justo.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2002 12:00 AM
08-21-2002 12:00 AM
Re: Shell script pipe (STDIN/STDOUT/STDERR)
The big point is NOT, what is comming after the command - like "killme.sh -f /tmp/file.txt", but what might be piped in to it or not!
So the real question is - is it somehow possible to check for pipe-in, like "cat /tmp/file.txt | killme.sh".
If there is some, you can just do:
STDIN1=`cat`
and that's done, but if nothing is comming in, it will HANG!!! ... till EOF ups!!!
Kind Regards
Bjarne
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2002 12:03 AM
08-21-2002 12:03 AM
SolutionThe shell is pretty limited in its ability to check the status of a file descriptor. However, you can differentiate between the examples you supplied by checking if standard input is from a terminal
if [[ -t 0 ]];
then
although this won't work for a cron job for instance.
Another possibility is to use the read command to try to read data from standard input.
while read RECORD
do
done
Regards,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2002 01:36 AM
08-21-2002 01:36 AM
Re: Shell script pipe (STDIN/STDOUT/STDERR)
#!/usr/bin/sh
if [ -t 0 ]
then
echo "No piped input"
else
read data
echo "Piped input is $data"
fi
echo "Command Line parameters are $*"