Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Understanding the output command Post 302386816 by Corona688 on Wednesday 13th of January 2010 04:54:30 PM
Old 01-13-2010
Quote:
Originally Posted by Ariean
I am missing something what do u mean by standard error? i understand standard output is the output printed on screen when i execute the script. But i didn't understand "2>&1" part, whats happening over there?

Thanks,
Ariean
By tradition, a UNIX process has three default streams: standard input(stdin), standard output(stdout), and standard error(stderr). stdin is represents the terminal keyboard as file descriptor 0, stdout represents the terminal screen as file descriptor 1, and stderr is also directed to the terminal screen as file descriptor 2.

The idea with having two files going to the terminal is to keep data and error messages separate. You can redirect the data output of a process into a file and still see human-readable error messages on your terminal. It also helps keep error messages OUT of data files since other programs probably won't need or understand them.

Here they're redirecting both stdout and stderr into the data file, for better or for worse. The "2>&1" bit tells it to redirect FD 2, stderr, to the same destination as FD 1, stdout.
This User Gave Thanks to Corona688 For This Post:
 

10 More Discussions You Might Find Interesting

1. OS X (Apple)

Ifconfig output - help understanding flags 'Smart, Simplex', etc

Hi - Trying to understand a few things from an ifconfig -a output - can't seem to find info anywhere on the net. Specifically - looking to understand the following: Flags=8863 Smart Running (is this the same as UP) Simplex inet6 supported media: autoselect - does that imply the... (1 Reply)
Discussion started by: littlefrog
1 Replies

2. UNIX for Dummies Questions & Answers

Help Understanding Output and question about /dev/

Hi, I am having some problems understanding the info from the following output: Disk /dev/sda: 17849 cylinders, 255 heads, 63 sectors/track Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0 Device Boot Start End #cyls #blocks Id System /dev/sda1 *... (5 Replies)
Discussion started by: mojoman
5 Replies

3. Shell Programming and Scripting

understanding mv command

hi i was moving a file from one directory to another with the following cmmand mv /home/hsghh/dfd/parent/file.txt . while doing so i i accidently mv /home/hsghh/dfd/dfd . although i gave ctrl c and terminate the move command some of the file are missing in the parent directory and... (1 Reply)
Discussion started by: saravanan71184
1 Replies

4. Shell Programming and Scripting

Understanding the output of TOP

ok, so I have a script im running on a linux box that uses "egrep" a lot. now, when i run this script, i check the TOP to see how much system resource it is using. the "top" command gives the following output: last pid: 25384; load avg: 1.06, 1.04, 0.76; up 351+06:30:24 ... (0 Replies)
Discussion started by: SkySmart
0 Replies

5. Solaris

Understanding 'du' command

Hi I have a questions related 2 commands : 'du' and 'ls'. Why is the difference between output of 'du' and 'ls' cmd's ? Command 'du' : ------------------ jakubn@server1 /home/jakubn $ du -s * 4 engine.ksh 1331 scripts 'du -s *' ---> shows block count size on disk (512 Bytes... (5 Replies)
Discussion started by: presul
5 Replies

6. UNIX for Dummies Questions & Answers

Understanding nm command output

After running nm command on any object file from out put can we get to know that wheather a symbol is a call to a function or definition of function ? I am searching a class and function definitions inside many .so files. I have 3 files which contain the symbol but I don't know wheather they... (2 Replies)
Discussion started by: yatrik007
2 Replies

7. Shell Programming and Scripting

Understanding the output of fwtmp

Hi all, First time post, so please be gentle. :) I'm writing a Solaris 10 ksh script to retrieve details of logins and logouts using specific user names. The details I want are quite basic - the username, the computer logged in from, and the date and time the user logged in and logged off.... (6 Replies)
Discussion started by: confusedAdmin
6 Replies

8. Red Hat

Command understanding the output file destination in case of standard output!!!!!

I ran the following command. cat abc.c > abc.c I got message the following message from command cat: cat: abc.c : input file is same as the output file How the command came to know of the destination file name as the command is sending output to standard file. (3 Replies)
Discussion started by: ravisingh
3 Replies

9. UNIX for Advanced & Expert Users

Understanding output of "last" command

Hello, Been looking through Google, and I don't see a direct answer to this: # last ... abcd pts/1 srever02 Mon Feb 23 07:56 - 07:56 (00:00) abcd sshd server02 Mon Feb 23 07:56 - 07:56 (00:00) klmn sshd ... (2 Replies)
Discussion started by: kitykitykity
2 Replies

10. Shell Programming and Scripting

Insert title as output of command to appended file if no output from command

I am using UNIX to create a script on our system. I have setup my commands to append their output to an outage file. However, some of the commands return no output and so I would like something to take their place. What I need The following command is placed at the prompt: TICLI... (4 Replies)
Discussion started by: jbrass
4 Replies
STDIN(3)                                                     Linux Programmer's Manual                                                    STDIN(3)

NAME
stdin, stdout, stderr - standard I/O streams SYNOPSIS
#include <stdio.h> extern FILE *stdin; extern FILE *stdout; extern FILE *stderr; DESCRIPTION
Under normal circumstances every UNIX program has three streams opened for it when it starts up, one for input, one for output, and one for printing diagnostic or error messages. These are typically attached to the user's terminal (see tty(4)) but might instead refer to files or other devices, depending on what the parent process chose to set up. (See also the "Redirection" section of sh(1).) The input stream is referred to as "standard input"; the output stream is referred to as "standard output"; and the error stream is referred to as "standard error". These terms are abbreviated to form the symbols used to refer to these files, namely stdin, stdout, and stderr. Each of these symbols is a stdio(3) macro of type pointer to FILE, and can be used with functions like fprintf(3) or fread(3). Since FILEs are a buffering wrapper around UNIX file descriptors, the same underlying files may also be accessed using the raw UNIX file interface, that is, the functions like read(2) and lseek(2). On program startup, the integer file descriptors associated with the streams stdin, stdout, and stderr are 0, 1, and 2, respectively. The preprocessor symbols STDIN_FILENO, STDOUT_FILENO, and STDERR_FILENO are defined with these values in <unistd.h>. (Applying freopen(3) to one of these streams can change the file descriptor number associated with the stream.) Note that mixing use of FILEs and raw file descriptors can produce unexpected results and should generally be avoided. (For the masochis- tic among you: POSIX.1, section 8.2.3, describes in detail how this interaction is supposed to work.) A general rule is that file descrip- tors are handled in the kernel, while stdio is just a library. This means for example, that after an exec(3), the child inherits all open file descriptors, but all old streams have become inaccessible. Since the symbols stdin, stdout, and stderr are specified to be macros, assigning to them is nonportable. The standard streams can be made to refer to different files with help of the library function freopen(3), specially introduced to make it possible to reassign stdin, std- out, and stderr. The standard streams are closed by a call to exit(3) and by normal program termination. CONFORMING TO
The stdin, stdout, and stderr macros conform to C89 and this standard also stipulates that these three streams shall be open at program startup. NOTES
The stream stderr is unbuffered. The stream stdout is line-buffered when it points to a terminal. Partial lines will not appear until fflush(3) or exit(3) is called, or a newline is printed. This can produce unexpected results, especially with debugging output. The buffering mode of the standard streams (or any other stream) can be changed using the setbuf(3) or setvbuf(3) call. Note that in case stdin is associated with a terminal, there may also be input buffering in the terminal driver, entirely unrelated to stdio buffering. (Indeed, normally terminal input is line buffered in the kernel.) This kernel input handling can be modified using calls like tcse- tattr(3); see also stty(1), and termios(3). SEE ALSO
csh(1), sh(1), open(2), fopen(3), stdio(3) COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/. Linux 2017-09-15 STDIN(3)
All times are GMT -4. The time now is 04:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy