Linux Topic
   >  What is an Operating System?
   >  Why use Linux?
   >  When not to use Linux
   >  Can I run Windows Apps under Linux?
   >  Linux Costings verses Windows
   >  Different Linux Distros
   >  An Introduction to Ubuntu
   >  An Introduction to Fedora
   >  An Introduction to Mint
   >  An Introduction to Puppy
   >  An Introduction to TinyCore
   >  An Introduction to MEPIS
   >  An Introduction to Zorin
   >  Recommend Me a Linux Distro!
   >  Sourcing a Linux Distribution
   >  Downloading a Linux Image
   >  Installing & Using BitTorrent
   >  Making a Boot Disc
   >  Installing Ubuntu Linux
   >  Patching Ubuntu Linux
   >  Installing Puppy Linux
   >  Installing Fedora Linux
   >  Patching Fedora Linux
   >  Installing TinyCore Linux
   >  Installing Linux Mint
   >  Patching Linux Mint
   >  Installing SimplyMEPIS & AntiX Linux
   >  Installing Fedora 17
   >  Creating Fedora Live USBs
   >  Installing Multimedia Support in Fedora
   >  The Gnome GUI
   >  Customising Gnome Panels
   >  Customising the Desktop
   >  Using Workspaces
   >  Undeleting Files
   >  Using Gnome to View Folders
   >  Customising Menus
   >  The Fedora Gnome 3 GUI
   >  Using the Favourites List in Fedora
   >  Using the  Gnome 3.x Activities Area
   >  Using Workspaces in Gnome 3.x
   >  Adding  Applications to Gnome
   >  Customising the 3.x Desktop
   >  Using Gnome to View Folders
   >  The Linux Mint Gnome 3 GUI
   >  The Zorin OS Gnome 3 GUI
   >  The KDE Desktop
   >  Configuring a KDE Panel
   >  Customizing the KDE Desktop
   >  Installing New KDE Widgets
   >  The Kubuntu KDE Desktop
   >  The Fedora KDE Desktop
   >  The Mint KDE Desktop
   >  The SimplyMEPIS KDE Desktop
   >  The LXDE Desktop
   >  Customizing the LXDE Desktop
   >  The Linux Mint LXDE Desktop
   >  The Lubuntu LXDE Desktop
   >  The AntiX LXDE Desktop
   >  The Fedora LXDE Desktop
   >  The Zorin Lite LXDE Desktop
   >  The Fedora Xfce Desktop
   >  The Xubuntu Desktop
   >  An Xfce Desktop Overview
   >  Customizing the Xfce Desktop
   >  Introducing the Unity Desktop
   >  Using the Unity Desktop
   >  Customizing the Unity Desktop
   >  Using Workspaces in Unity
   >  Disabling Unity
   >  Unity Keyboard Shortcuts
   >  The TinyCore Desktop
   >  The Puppy Desktop
   >  The Puppy File Manager
   >  Why use the Command Line?
   >  Common Linux Commands
   >  Directory Structure
   >  Using Regular Expressions
   >  $STDIN; $STDOUT and $STDERR
   >  IO Redirection and Pipes
   >  Housekeeping Duties
   >  Auto Starting Applications
   >  Monitoring System Resources
   >  Controlling Processes
   >  Linux Log Files
   >  Shell Scripts
   >  Using Comments
   >  Passing Arguments to Scripts
   >  Using Conditional Statements
   >  Using Loop Statements
   >  Reading and Writing Files
   >  Script Permissions
   >  Cron and Scheduling
   >  A Scripting Example
   >  Other Scripting Languages
   >  Index of Sections

 

$STDIN, $STDOUT and $STDERR

The Difference between $STDIN, $STDOUT and $STDERR

Pretty much every Linux command implemented uses three basic Input/Output streams -one for input and two for output:

I/O DescriptorDescription
$STDIN

This is the input stream that the command/script will use. It defines where the input should come from. For example, in the command "more oldfile1", $STDIN will be set to the file oldfile1.

Note: the default $STDIN for most functions is the keyboard

$STDOUT

This is the output stream that the command/script will use. It defines where the output should go. For example, in the command "cp oldfile1 > newfile", $STDOUT will be set to the file newfile.

Note: the default $STDOUT for most functions is the screen

$STDERR

This is the error message stream that the command/script will use. It defines where any warnings/errors should be sent. For example, in the command "cp oldfile1 newfile 2> myerrors", any errors will be set to the file myerrors.

Note: the default $STDERR for most functions is the screen

Having these three basic streams makes I/O Redirection possible for almost all Linux commands : i.e. the ability to change where the input comes from and the output and errors sent. When using Linux commands (-and especially when combining them), always be aware of the above three streams and what they should be set to. For example, consider this command to search files under the / for the string "abc":

$ grep "abc" /*
/* this is file "abc" */
grep: /lost+found: Permission denied
grep: /root: Permission denied

The $STDIN for this command has been set to all the files in the root directory (/*) but which stream(s) have the screen output come from? Well, it's actually come from two: the first line (valid output) has come from $STDOUT and the second and third lines (error messages) have come from $STDERR.


HomeSite IndexDesktop GuideServer GuideHints and TipsHardware CornerVideo SectionContact Us

 sitelock verified Firefox Download Button