stderr redirection


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers stderr redirection
# 1  
Old 12-12-2002
stderr redirection

Does anyone know away of redirecting the stderr for a bourne or korn shell script to a file.
# 2  
Old 12-12-2002
I though it was the same for all shells?

This shold produce a file 'junk.txt' with an error from stderr

Code:
$ RunFail > junk.txt 2>$1

# 3  
Old 12-12-2002
Actually it's:
$ RunFail > junk.txt 2>&1

That is you need an ampersand, not a dollar sign. And that syntax will not work with csh or csh clones.
# 4  
Old 12-12-2002
Thanks Perderabo.

I I rewrite it as:
RunFail >> junk.txt 2>>&1

will it append to the file?
# 5  
Old 12-12-2002
There is no such thing as 2>>&1

>> junk.txt
will open the file in append mode and attach it to fd 1

2>&1
will duplicate fd 1 and attach it to fd 2. You use this form for everything. It does not matter how fd 1 came to exist.
# 6  
Old 12-12-2002
Opps to my typo Smilie

thanks Perderabo
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Doubt regarding stderr

Hi All, I am writing a shell script code. and i want the stderr to be send to a file and the stdout to be displayed in terminal. In my shell script code i use a read command to get data from user.read -r -p "Enter the type :" data and while i execute my script i use./my_script.sh 2>... (4 Replies)
Discussion started by: Vinoth R
4 Replies

2. Shell Programming and Scripting

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: >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... (5 Replies)
Discussion started by: animesharma
5 Replies

3. 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

4. UNIX for Dummies Questions & Answers

how to get stderr

Hello I try to store stderr into a variable, then if this var is not empty i send an email and stop my script. I think my problem is due of "<$dump" into my command line. my bad command line (see samples below on this post) if ! $returnedStr ; then echo ERROR READING DUMP: ... (8 Replies)
Discussion started by: giova
8 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

Append stderr

Hi everybody. I was used to redirect stderr to a file in this way, calling a generic script:./myScript &> output.logBut now I need something more sophisticated...Inside a bash script I launch an executable in this way:${command} >> "${globalLogFile}"So I redirect the stdout into globalLogFile.... (14 Replies)
Discussion started by: canduc17
14 Replies

7. 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

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. 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

10. Programming

stderr

in fprint(stderr, "lkjalsdi\n"); what does stderr mean? thanks (1 Reply)
Discussion started by: dell9
1 Replies
Login or Register to Ask a Question