Operating System - HP-UX
1830256 Members
2026 Online
110000 Solutions
New Discussion

Redirect output to /dev/null

 
SOLVED
Go to solution
hpuxrox
Respected Contributor

Redirect output to /dev/null

Hi,

I am looking for examples on how to redirect output to /dev/null. Currently, we use

> /dev/null 2>&1

But I though I remember a shorter version of this with two && in the syntax?

Any of you gurus know the syntax?
12 REPLIES 12
Victor BERRIDGE
Honored Contributor

Re: Redirect output to /dev/null

Hi,
I dont see how with &&: && means what follows (&&) will be executed only if the preceding instructions complete without errors (return a 0 value)

All the best
Victor
Mark Grant
Honored Contributor

Re: Redirect output to /dev/null

No, your syntax is correct. You can not use &&
Never preceed any demonstration with anything more predictive than "watch this"
hpuxrox
Respected Contributor

Re: Redirect output to /dev/null

maybe it was &>- or something to that extent
Geoff Wild
Honored Contributor

Re: Redirect output to /dev/null

That is the correct way:

>/dev/null 2>&1

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
hpuxrox
Respected Contributor

Re: Redirect output to /dev/null

There is a shorter version of the syntax, Ill keep looking in my notes. thanks
MarkSyder
Honored Contributor

Re: Redirect output to /dev/null

If you find it could you please share it with us? I for one am ingrigued!

Mark Syder (like the drink but spelt different)
The triumph of evil requires only that good men do nothing
Mark Grant
Honored Contributor

Re: Redirect output to /dev/null

Yates,

I hope you have a lot of patience because you will be studying those notes for some time.

How much shorter can it be! You need to have the "/dev/null" in there somewhere which leaves us 6 compulsory characters if we are also re-direct the standard error. Even you reduce this syntax by 50% you are only going to save three characters. However, if you like, do this

"ln /dev/null /n"

Thereafter, your syntax could be

>/n 2>&1

This gets it much shorter.
Never preceed any demonstration with anything more predictive than "watch this"
Michael Schulte zur Sur
Honored Contributor
Solution

Re: Redirect output to /dev/null

Hi,

Yates is right. Ih ksh you find:
<&- The standard input is closed. The standard output is closed using >&-

never paid any attention to that.

greetings

Michael
Michael Schulte zur Sur
Honored Contributor

Re: Redirect output to /dev/null

One more,

this still would be
command &>- 2>&1

greetings,

Michael
Mark Grant
Honored Contributor

Re: Redirect output to /dev/null

closing standard input and closing standard output is not the same as redirecting to /dev/null.
Never preceed any demonstration with anything more predictive than "watch this"
Michael Schulte zur Sur
Honored Contributor

Re: Redirect output to /dev/null

Mark,

I see, what you mean. a programme that does get it's stdout closed might abort or burden the cpu.

Michael
Mark Grant
Honored Contributor

Re: Redirect output to /dev/null

Also, it doesn't close the standard error so this is NOT a substitute syntax for >/dev/null 2>&1.

Never preceed any demonstration with anything more predictive than "watch this"