stderr redirection not working


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting stderr redirection not working
# 1  
Old 02-24-2012
stderr redirection not working

I am running tcsh/csh shell on my machine. lately i have realized my stderr file redirection is not working.

Please find the terminal logs as below:

Code:
>echo b c >>& log
>cat log
b c
>echo $a b c >>& log
a: Undefined variable.
>cat log
b c

I have never faced such issues, hence not sure how to debug or troubleshoot. Please advice!

Last edited by Scott; 02-24-2012 at 03:43 AM.. Reason: Code tags
# 2  
Old 02-24-2012
try setting some values to the variable a , like
Code:
set a = 12

then echo $a b c
# 3  
Old 02-24-2012
@codemaniac

I understand that, but thats not my intention. i want to redirect the stderr into a file.
Can you try the line:
Code:
>echo $a b c >>& log

in your unix terminal(tcsh) and see if it fails.

Last edited by Scott; 02-24-2012 at 03:43 AM.. Reason: Code tags
# 4  
Old 02-24-2012
Code:
(echo $a ) >& log

Guru.
# 5  
Old 02-24-2012
As suggested by guru ,

try something like

Code:
( echo $a b c > /dev/stdin ) > & log

# 6  
Old 02-24-2012
An alterate method of redirection is using tee. While I use >& or >>& , i am altogether blocking any output to be displayed on terminal. Is there a way I can do both, that is: for each statement
a) direct stdout+stderr to a file.
b) display stdout+stderr on terminal

I need to confirm if i can use something like this(below) to meet my requirements
Code:
>csh ./script_name | tee -a log

In my case it only directs stdout to log file and blocks stderr.

Last edited by Franklin52; 02-24-2012 at 03:42 AM.. Reason: Please use code tags for code and data samples, thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

>& redirection not working within csh script

I'm having a strange problem with basic >& output redirection to a simple log file in csh. When I run this particular output redirection on the command line, it works, but then when I run the same output redirection command >& in my c shell script, I get a blank log file. Nothing is output to the... (5 Replies)
Discussion started by: silencio
5 Replies

2. Shell Programming and Scripting

Cygwin script log redirection not working well

I have a simple script which will send a curl request and redirect the output to a log file. for i in {1..20} do curl google.com -is >>log.log & echo "request # $i" >> log.log doneAfter it completes the execution, if I run the following command I should see 20 lines because I am printing... (4 Replies)
Discussion started by: heykiran
4 Replies

3. Shell Programming and Scripting

Command output redirection in script not working

I need to count the number of lines in a .txt file and put it in a variable. I am using the following code #!/bin/bash count = $(wc -l "some file.txt" | awk '{print$1}') echo $count It is giving the following error. line3: count: command not foundWhat am I doing wrong here? :confused: (7 Replies)
Discussion started by: haritha.gorijav
7 Replies

4. Shell Programming and Scripting

stdout, stderr redirection

Hi all, can someone help me with the next redirection? i want to redirect the stdout+stderr of a command to the same file (this i can do by prog &> file) but in addition i want to redirect only the stderr to a different file. how can i do this please? (in BASH) thanks. (4 Replies)
Discussion started by: eee
4 Replies

5. Shell Programming and Scripting

STDOUT and STDERR redirection within a script

Hello all, I have a for loop executing in a script that I want to redirect STDOUT to screen and to file, while directing STDERR to the bit bucket. Here is the general sentax of what I'm doing: for i in thingy do some_command ${i} done 1>&1 | tee ${LOGFILE} 2> /dev/null What I am... (2 Replies)
Discussion started by: LinuxRacr
2 Replies

6. Shell Programming and Scripting

Why stderr file descriptor redirection makes ksh's "select" construct hang.

I am trying to use one global declaration --> "exec 2>$ERR" to capture all stderr outputs that may occur anywhere in my script. Then close it at the end of the script using --> "exec 2<&-" I am using KSH on Solaris 8. KSH Version M-11/16/88i If I comment two "exec .." statements in the... (11 Replies)
Discussion started by: kchinnam
11 Replies

7. UNIX for Dummies Questions & Answers

Redirection not working as expected

Portion of my script below : if ; then NUMBEROFFEILDS=`cat ${BASE_SCRIPT_LOC}/standardfilecleanup.lst|grep -w ${db_file_path}|awk -F: '{print NF}'` COUNT=4 while ; do awk_var="$"`echo $COUNT` file_name1=`cat ${BASE_SCRIPT_LOC}/standardfilecleanup.lst|grep -w... (1 Reply)
Discussion started by: findprakash
1 Replies

8. Shell Programming and Scripting

csh stderr redirection

Hi everyone, Simple scripting question here. I have: #!/bin/csh if ( -e $HOME/*.core) then rm -f $HOME/*.core >& /dev/null else echo "No core files to delete." endif But I keep getting the /home/user/*.core: no match dialog. How can I suppress this? or, why is... (0 Replies)
Discussion started by: jolok
0 Replies

9. UNIX for Dummies Questions & Answers

stderr redirection

Does anyone know away of redirecting the stderr for a bourne or korn shell script to a file. (5 Replies)
Discussion started by: blakmk
5 Replies

10. Shell Programming and Scripting

stderr redirection in csh script

Man pages....look at the man pages. If you don't have them, you can find them on-line. Read them when you have nothing better to do. Find new commands and new ways of doing things. The answer: The only way to direct the standard output and standard error separately is by invoking... (0 Replies)
Discussion started by: thehoghunter
0 Replies
Login or Register to Ask a Question