Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

C-shell :: redirecting stderr to /dev/null

2,751 views
Skip to first unread message

Generic Usenet Account

unread,
Apr 7, 2005, 2:15:01 PM4/7/05
to
What is the easiest way to redirect the standard error to a null file
in C-shell? I am looking for something akin to what we do in ksh:

command 2> /dev/null

Thanks in advance,
Bhat

Dragan Cvetkovic

unread,
Apr 7, 2005, 2:20:37 PM4/7/05
to
"Generic Usenet Account" <use...@sta.samsung.com> writes:

> What is the easiest way to redirect the standard error to a null file
> in C-shell? I am looking for something akin to what we do in ksh:
>
> command 2> /dev/null
>

Can't be done. That's one of C shell limitations. Check "Csh Programming
Considered Harmful" for more of it at

http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/


Bye, Dragan


--
Dragan Cvetkovic,

To be or not to be is true. G. Boole No it isn't. L. E. J. Brouwer

!!! Sender/From address is bogus. Use reply-to one !!!

Keith Thompson

unread,
Apr 7, 2005, 5:59:35 PM4/7/05
to
"Generic Usenet Account" <use...@sta.samsung.com> writes:
> What is the easiest way to redirect the standard error to a null file
> in C-shell? I am looking for something akin to what we do in ksh:
>
> command 2> /dev/null

You can't do it directly, but there are workarounds.

If stdout happens to be /dev/tty, you can use:

( command > /dev/tty ) >& /dev/null

Or you can do this:

sh -c 'command 2> /dev/null'

--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.

Generic Usenet Account

unread,
Apr 8, 2005, 10:56:32 AM4/8/05
to
Dragan Cvetkovic wrote:

> Can't be done. That's one of C shell limitations. Check "Csh
Programming
> Considered Harmful" for more of it at
>
> http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/
>
>
> Bye, Dragan
>
>

There is one thing about C-shell that I really like and that is the
Variable Modifier feature. I mean:

:h >>-->> Remove a trailing pathname component, leaving the head
[similar to dirname]

:t >>-->> Remove all leading pathname components, leaving the tail
[similar to basename]

And my personal favorites...

:r >>-->> Remove a trailing extension, leaving the root
:e >>-->> Remove all but the extension


Is there a good equivalent for :r or :e in non C-shell shells?

Thanks,
Bhat

Måns Rullgård

unread,
Apr 8, 2005, 11:20:33 AM4/8/05
to
"Generic Usenet Account" <use...@sta.samsung.com> writes:

> Dragan Cvetkovic wrote:
>
>> Can't be done. That's one of C shell limitations. Check "Csh Programming
>> Considered Harmful" for more of it at
>>
>> http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/
>>
>>
>> Bye, Dragan
>>
>>
>
> There is one thing about C-shell that I really like and that is the
> Variable Modifier feature. I mean:

Bash can do those things in a more generic way.

> :h >>-->> Remove a trailing pathname component, leaving the head
> [similar to dirname]

${var%/*}

> :t >>-->> Remove all leading pathname components, leaving the tail
> [similar to basename]

${var##*/}

> And my personal favorites...
>
> :r >>-->> Remove a trailing extension, leaving the root

${var%.*}

> :e >>-->> Remove all but the extension

${var##*.}

> Is there a good equivalent for :r or :e in non C-shell shells?

See above.

--
Måns Rullgård
m...@inprovide.com

Icarus Sparry

unread,
Apr 8, 2005, 11:22:12 AM4/8/05
to
On Fri, 08 Apr 2005 07:56:32 -0700, Generic Usenet Account wrote:

> Dragan Cvetkovic wrote:
> There is one thing about C-shell that I really like and that is the
> Variable Modifier feature. I mean:
>
> :h >>-->> Remove a trailing pathname component, leaving the head
> [similar to dirname]
>
> :t >>-->> Remove all leading pathname components, leaving the tail
> [similar to basename]
>
> And my personal favorites...
>
> :r >>-->> Remove a trailing extension, leaving the root
> :e >>-->> Remove all but the extension
>
>
> Is there a good equivalent for :r or :e in non C-shell shells?

:r ${var%.*}
:e ${var##*.}

are reasonable approximations.

Paul D. Smith

unread,
Apr 8, 2005, 3:19:56 PM4/8/05
to
%% Måns Rullgård <m...@inprovide.com> writes:

mr> Bash can do those things in a more generic way.

The %, %%, #, and ## modifiers are not bash-specific: they're defined in
the POSIX spec for sh.

--
-------------------------------------------------------------------------------
Paul D. Smith <psm...@nortel.com> HASMAT--HA Software Mthds & Tools
"Please remain calm...I may be mad, but I am a professional." --Mad Scientist
-------------------------------------------------------------------------------
These are my opinions---Nortel Networks takes no responsibility for them.

Måns Rullgård

unread,
Apr 8, 2005, 3:43:41 PM4/8/05
to
"Paul D. Smith" <psm...@nortel.com> writes:

> %% Måns Rullgård <m...@inprovide.com> writes:
>
> mr> Bash can do those things in a more generic way.
>
> The %, %%, #, and ## modifiers are not bash-specific: they're defined in
> the POSIX spec for sh.

Thanks for the clarification. I wasn't sure it was POSIX, and wanted
to avoid being corrected in the other direction.

--
Måns Rullgård
m...@inprovide.com

0 new messages