[comp.unix.shell] pipe equivalent to /dev/null ???

oscarh@hpdmd48.boi.hp.com (Oscar Herrera) (09/10/90)

Is there an equivalent 'pipe' like entity to /dev/null ?
What I'd like to do is something like this 
	anycommand | bitbucket

Oscar Herrera

oscarh@hpdmd48.boi.hp.com (Oscar Herrera) (09/10/90)

||Is there an equivalent 'pipe' like entity to /dev/null ?
||What I'd like to do is something like this 
||	anycommand | bitbucket
||
||Oscar Herrera
||----------

	Well, I found the answer to my own question.

		touch bitbucket
		chmod +x bitbucket

	Then    
		ll | bitbucket      

	works well.

Oscar Herrera

cjc@ulysses.att.com (Chris Calabrese) (09/10/90)

How about:
	... | cat > /dev/null

Always works for me.

Short of that, it should be a trivial C program.
Something like:

	main() {
		char buffer[1024];
		while(! read(0, buffer, 1024))
			continue;
	}
Name:			Christopher J. Calabrese
Brain loaned to:	AT&T Bell Laboratories, Murray Hill, NJ
att!ulysses!cjc		cjc@ulysses.att.com
Obligatory Quote:	``pher - gr. vb. to schlep.  phospher - to schlep light.philosopher - to schlep thoughts.''

de5@de5.CTD.ORNL.GOV (Dave Sill) (09/10/90)

In article <8720002@hpdmd48.boi.hp.com>, oscarh@hpdmd48.boi.hp.com (Oscar Herrera) writes:
>||Is there an equivalent 'pipe' like entity to /dev/null ?
>
>>		touch bitbucket
>		chmod +x bitbucket
>
>	Then    
>		ll | bitbucket      

Even better, use `true'.  It's already there.

-- 
Dave Sill (de5@ornl.gov)
Martin Marietta Energy Systems
Workstation Support

les@chinet.chi.il.us (Leslie Mikesell) (09/11/90)

In article <8720002@hpdmd48.boi.hp.com> oscarh@hpdmd48.boi.hp.com (Oscar Herrera) writes:

>||Is there an equivalent 'pipe' like entity to /dev/null ?
>||What I'd like to do is something like this 
>||	anycommand | bitbucket
>	Well, I found the answer to my own question.
>		touch bitbucket
>		chmod +x bitbucket
>	Then    
>		ll | bitbucket      
>	works well.

This will work only so long as the process generating the output doesn't
generate enough data to fill a pipe buffer.  Since your "null" program
isn't actually going to read anything, when the pipe fills, the writing
program will block. 
A more reasonable method would be to use "|cat >/dev/null", though the
result is the same as a simple ">/dev/null".  Why did you want the
pipe, anyway?

Les Mikesell
  les@chinet.chi.il.us

dbrooks@osf.org (David Brooks) (09/11/90)

In article <1990Sep11.013805.3594@chinet.chi.il.us>,
les@chinet.chi.il.us (Leslie Mikesell) writes:
|> In article <8720002@hpdmd48.boi.hp.com> oscarh@hpdmd48.boi.hp.com
(Oscar Herrera) writes:
|> 
|> >||Is there an equivalent 'pipe' like entity to /dev/null ?
|> A more reasonable method would be to use "|cat >/dev/null", though
the
|> result is the same as a simple ">/dev/null".

If you want to save keystrokes at the expense of compute time:

	|sed d

Not relevant if you are putting it in a script, though.

(several :-), by the way).
-- 
David Brooks				dbrooks@osf.org
Systems Engineering, OSF		uunet!osf.org!dbrooks
Experience Hackvergnuegen!

oscarh@hpdmd48.boi.hp.com (Oscar Herrera) (09/11/90)

|A more reasonable method would be to use "|cat >/dev/null", though the
|result is the same as a simple ">/dev/null".  Why did you want the
|pipe, anyway?
|
|Les Mikesell
|  les@chinet.chi.il.us
|----------

	Thanks for all the responses.  I wanted to use a pipe because
	I wanted to bitbucket the output of an RMBUX command.  It turns
	out that RMBUX programmatic output redirection requires a
	statement like   PRINTER IS "| ...   
	involving a pipe.  The final solution I used was 
		PRINTER IS "| cat >/dev/null"

	Oscar Herrera
	oscarh@hpdmmad

rns@se-sd.SanDiego.NCR.COM (Rick Schubert) (09/12/90)

In <8720001@hpdmd48.boi.hp.com> oscarh@hpdmd48.boi.hp.com (Oscar Herrera) writes:

>Is there an equivalent 'pipe' like entity to /dev/null ?
>What I'd like to do is something like this 
>	anycommand | bitbucket

I've seen responses of
	anycommand | true
and
	anycommand | cat >/dev/null

What about
	anycommand | :
?

I'm not sure if this is shell-specific, but it works with the Bourne
shell and the C shell, at least on our system.

(You mean you thought ":" was a comment indicator?  Try

	: > somefilename

)

-- Rick Schubert (rns@se-sd.sandiego.NCR.COM)

merlyn@iwarp.intel.com (Randal Schwartz) (09/12/90)

In article <8720002@hpdmd48.boi.hp.com>, oscarh@hpdmd48 (Oscar Herrera) writes:
| ||Is there an equivalent 'pipe' like entity to /dev/null ?
| ||What I'd like to do is something like this 
| ||	anycommand | bitbucket
| ||
| ||Oscar Herrera
| ||----------
| 
| 	Well, I found the answer to my own question.
| 
| 		touch bitbucket
| 		chmod +x bitbucket
| 
| 	Then    
| 		ll | bitbucket      
| 
| 	works well.

Until the ll output pipe fills up.

My first suggestion is "why?"  For example, if I wanted the ll
output to go nowhere, I would type:

	ll >/dev/null

Second, if you *really* need a process, use

	cat >/dev/null

as in:

	ll | cat >/dev/null

yucky yucky kludge.  But it fits your requested parameters.

Just another Unix hacker,
-- 
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III      |
| merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/

jbr0@cbnews.att.com (joseph.a.brownlee) (09/13/90)

In article <3841@se-sd.SanDiego.NCR.COM>, rns@se-sd.SanDiego.NCR.COM (Rick
Schubert) writes:
> In <8720001@hpdmd48.boi.hp.com> oscarh@hpdmd48.boi.hp.com (Oscar Herrera)
> writes:
> >Is there an equivalent 'pipe' like entity to /dev/null ?
> >What I'd like to do is something like this 
> >	anycommand | bitbucket
> 
> I've seen responses of
> 	anycommand | true
> and
> 	anycommand | cat >/dev/null
> 
> What about
> 	anycommand | :
> 
> I'm not sure if this is shell-specific, but it works with the Bourne
> shell and the C shell, at least on our system.

Yes, that works, and it works in the Korn shell as well.  At least in the
context shown above, it is logically equivalent to the "anycommand | true"
case.

-- 
   -      _   Joe Brownlee, Analysts International Corp. @ AT&T Network Systems
  /_\  @ / `  471 E Broad St, Suite 1610, Columbus, Ohio 43215   (614) 860-7461
 /   \ | \_,  E-mail: jbr@cblph.att.com     Who pays attention to what _I_ say?
 "Scotty, we need warp drive in 3 minutes or we're all dead!" --- James T. Kirk

cjc@ulysses.att.com (Chris Calabrese) (09/13/90)

In article <3841@se-sd.SanDiego.NCR.COM> rns@se-sd.SanDiego.NCR.COM (Rick Schubert) writes:
>In <8720001@hpdmd48.boi.hp.com> oscarh@hpdmd48.boi.hp.com (Oscar Herrera) writes:
>
>>Is there an equivalent 'pipe' like entity to /dev/null ?
>>What I'd like to do is something like this 
>>	anycommand | bitbucket
>
>I've seen responses of
>	anycommand | true
>and
>	anycommand | cat >/dev/null
>
>What about
>	anycommand | :
>?
>
>I'm not sure if this is shell-specific, but it works with the Bourne
>shell and the C shell, at least on our system.
>
>(You mean you thought ":" was a comment indicator?  Try
>
>	: > somefilename
>
>)
>
>-- Rick Schubert (rns@se-sd.sandiego.NCR.COM)

I've been following this thread for some time, and I have
to say that neither '... | true' nor '... | :' will do the trick.
I thought this would be obvious.
'true' and ':' don't read their stdin, thus the process feeding them
would block and never run.  This is hardly what happens with
'/dev/null'.

A slightly better approach than '... | cat > /dev/null' is a trivial
program which reads its input and creates no output.  In fact, I gave
source to just such a program (didn't test it, though) in a previous
posting in this thread.  It's pretty trivial.

On the other hand, ':' and 'true' are perfectly good
null pipe _sources_.  'true | ...' and ': | ...' do exactly the same
thing is '< /dev/null ...'.

What I really want to know is in what situation you _need_ a pipe,
when /dev/null already is there.  The only thing I can think of is
a C program which uses popen() explicity.  This, of course, flies in
the face of the UNIX tool building philosophy.

BTW, '/bin/true' is often implemented as something like:
	#	the true command
	:
Name:			Christopher J. Calabrese
Brain loaned to:	AT&T Bell Laboratories, Murray Hill, NJ
att!ulysses!cjc		cjc@ulysses.att.com
Obligatory Quote:	``pher - gr. vb. to schlep.  phospher - to schlep light.philosopher - to schlep thoughts.''

dave@dptechno.UUCP (Dave Lee) (09/14/90)

In article <3841@se-sd.SanDiego.NCR.COM> rns@se-sd.SanDiego.NCR.COM (Rick Schubert) writes:
>In <8720001@hpdmd48.boi.hp.com> oscarh@hpdmd48.boi.hp.com (Oscar Herrera) writes:
>
>>Is there an equivalent 'pipe' like entity to /dev/null ?
>>What I'd like to do is something like this 
>>	anycommand | bitbucket
>
>I've seen responses of
>	anycommand | true
>and
>	anycommand | cat >/dev/null
>
>What about
>	anycommand | :
>?
>
>I'm not sure if this is shell-specific, but it works with the Bourne
>shell and the C shell, at least on our system.
>


Beautiful !. Elegent and clean. (Although I still dont know why ">/dev/null"
wont do...)

I Tried this in /bin/csh on a HP-UX 7.0 system 9000/345 and got the most
interesting message

	Reset tty pgrp from 391 to 366

Then a quick "Jobs" command gives

	[2]  -Broken pipe          yes |


Another quick "Jobs" shows nothing.

a strings on /bin/csh shows
	Reset tty pgrp from %d to %d

Just what is this trying to say?  Am I supposed to change prgrp or is the shell
just telling me it has. 

Which shell, the parent or the forked ":" ?.



-- 
Dave Lee
uunet!dptechno!dave

dkeisen@Gang-of-Four.Stanford.EDU (Dave Eisen) (09/16/90)

In article <1990Sep11.013805.3594@chinet.chi.il.us> les@chinet.chi.il.us (Leslie Mikesell) writes:
>In article <8720002@hpdmd48.boi.hp.com> oscarh@hpdmd48.boi.hp.com (Oscar Herrera) writes:
>
>>	Well, I found the answer to my own question.
>>		touch bitbucket
>>		chmod +x bitbucket
>>		ll | bitbucket      
>
>This will work only so long as the process generating the output doesn't
>generate enough data to fill a pipe buffer.  Since your "null" program
>isn't actually going to read anything, when the pipe fills, the writing
>program will block. 

Small nit. As you said, there is a problem with the pipe buffer filling and 
the write hanging. More serious though is the problem that when bitbucket
runs and dies, any subsequent write by ll will result in ll receiving
a SIGPIPE (write to a pipe with no reader) signal and presumably
being killed.
--
Dave Eisen                      	    Home: (415) 323-9757
dkeisen@Gang-of-Four.Stanford.EDU           Office: (415) 967-5644
1447 N. Shoreline Blvd.
Mountain View, CA 94043

res@cbnews.att.com (Robert E. Stampfli) (09/16/90)

> >>Is there an equivalent 'pipe' like entity to /dev/null ?
> >
> >I've seen responses of
> >	anycommand | true
> 
> I've been following this thread for some time, and I have
> to say that neither '... | true' nor '... | :' will do the trick.
> 'true' and ':' don't read their stdin, thus the process feeding them
> would block and never run.

Several people have commented to this effect, but it is normally not true
that this sequence would block, at least not for long.  Rather, "true" would
execute and exit, and "anycommand" would then receive the broken pipe
signal.  Usually this would cause it to terminate.  The net result, however,
is that, although the sequence might appear to work, "anycommand" would
terminate abnormally and could not be guaranteed to do any side effects
which it might be expected to have done, say, after processing all of
its data.
-- 
Rob Stampfli	/ att.com!stampfli (uucp@work) / kd8wk@w8cqk (packet radio)
614-864-9377	/ osu-cis.cis.ohio-state.edu!kd8wk!res (uucp@home)

chris@mimsy.umd.edu (Chris Torek) (09/16/90)

In article <13731@ulysses.att.com> cjc@ulysses.att.com (Chris Calabrese)
writes:
>I've been following this thread for some time, and I have
>to say that neither '... | true' nor '... | :' will do the trick.
>I thought this would be obvious.

This much is correct, but:

>'true' and ':' don't read their stdin, thus the process feeding them
>would block and never run.

... several people have made this claim, and I cannot understand why.
Since this is going on in comp.unix.shell, and all the examples are
using shells, we can assume that the pipe is properly set up, i.e., the
process writing on it does not have it open for reading as well.  Since
`true' and `:' exit as soon as they are run, when the first process
first tries to write on the pipe it will get an error and a SIGPIPE
signal.

>A slightly better approach than '... | cat > /dev/null' is a trivial
>program which reads its input and creates no output.

Why is this better?  It saves one system call per pipe-read, but other
than that it takes more work and a separate program.  Writing to /dev/null
is very efficient (there are no user-to-kernel copies involved; indeed,
you can pass illegal addresses to write() if and only if you are writing
to /dev/null).
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 405 2750)
Domain:	chris@cs.umd.edu	Path:	uunet!mimsy!chris

oscarh@hpdmd48.boi.hp.com (Oscar Herrera) (09/17/90)

|....................................................  Writing to /dev/null
|is very efficient (there are no user-to-kernel copies involved; indeed,
|you can pass illegal addresses to write() if and only if you are writing
|to /dev/null).
|-- 

	Yes, writing to /dev/null is darn efficient.  Try the following
	(Bourne) and watch the idle time parameter in monitor go to zero

	while true
	do
	ps -ef >/dev/null
	done

	BTW, in case you are still wondering why I needed the a pipe 
	equivalent to /dev/null, it was so that in RMBUX ( Rocky Mountain
	BASIC under HPUX ) I could construct the following statement:

	1000 PRINTER IS "| cat >/dev/null"