LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-09-2013, 10:40 AM   #1
UltraJoe
LQ Newbie
 
Registered: Jun 2013
Posts: 1

Rep: Reputation: Disabled
Getting csh/tcsh to not word break ">&"


I've got some experience with bash, ksh, and the like, but the sysadmin has stuck many of us with tcsh instead. I try to perform a command such as:

find / -name foo -print

knowing full well I will get errors on some directories. Of course, in bash I can redirect diagnostic output with >>/dev/null and eliminate the noise. Trying to do that in tcsh, though, fails miserably. From what I can see, I should type

find / -name foo -print >/dev/tty >&/dev/null

but when I do that, the command gets word-broken into

find / -name foo -print > /dev/tty > & /dev/null

which tcsh doesn't want.

I realize I can simply /bin/bash -c "find...", but I'd like to know what I'm doing wrong with tcsh.
 
Old 07-09-2013, 11:37 AM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,654

Rep: Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255
It is listed as "ambiguous redirection".

You can get around that putting the initial redirection in parenthises:

Code:
(find / -name foo -print >/dev/tty) >&/dev/null
The reason this works is that the command "(...) >&/dev/null" redirects both stdout and stderr to /dev/null.
The enclosed command "find / -name foo -print >/dev/tty" then redirects stdout to /dev/tty. The evaluation on the command is from outer grouping () to inner, so the >& is evaluated before the inner command - thus disambiguating the > and the >&.

In my opinion, it is a stupid parser that doesn't tokenize > differently from the >& symbols. But this happens due to a single character token handling - thus when it sees ">" it uses the next character to identify whether it is stdout, or both stdout and stderr. When it sees a following ">&" it does detect that stdout has already been redirected... thus causing an "ambigeous" redirection since ">&" calls for both stdout and stderr to be redirected.

This situation could STILL be handled - if it allowed the ">&" token to appear first (redirecting both stdout and stderr), then allow for redirecting stdout.

This is the same problem that csh has (which is where tcsh is derived).
 
1 members found this post helpful.
  


Reply

Tags
csh, diagnostics, tcsh


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 02:03 AM
Shell Script: Find "Word" Run "Command" granatica Linux - Software 5 07-25-2007 08:42 AM
What is wrong in the statement: $line || echo "error" && break; nadavvin Linux - General 1 08-05-2006 06:25 AM
bash equivalence of tcsh "alias em "emacs \!:1 &""? rgiggs Slackware 3 07-29-2004 03:07 AM
CSH: "cmd >& file" or "cmd </dev/null >& file" stefanlasiewski Programming 1 09-08-2003 05:19 PM


All times are GMT -5. The time now is 10:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration