Re: Linux sys vars?

Top Page
Attachments:
Message as email
+ (text/plain)
+ (text/plain)
Delete this message
Reply to this message
Author: Dale Farnsworth
Date:  
To: plug-discuss
CC: 
Subject: Re: Linux sys vars?
> Hi,
>
> I keep seeing a reference to what looks like two pre-populated variables
> in shell scripts.  Actually this one is in a crontab.
>
> Something like this :  /home/user-name/directory-name/scriptname.php
> >/dev/null 2>&1
>
> What is the number 1 and 2?  Is there others?


Unix and copycats, like Linux use small non-negative integers to identify
files that may be read from or written to. They are known as file
descriptors. By convention, the first 3 file descriptors have a special
meaning. 0 is standard input, 1 is standard output, and 2 is standard
error.

Normally, each process inherits these 3 file descriptors from its
parent process but the shell allows you to "redirect" them to
other files.

Examples:
    echo hello >newfile    # Creates the file "newfile" and writes
                # "hello\n" to it.
    echo hello >/dev/null    # Writes "hello\n" to /dev/null, where it
                # disappears
    echo hello 2>newfile2    # Creates the file "newfile2" and puts
                # error messages from "echo hello" into it.
                # Since "echo hello" won't output any error
                # messages, "newfile2" will be an empty file.
    echo hello 2>&1        # Redirects the error output of the command
                # into the same file where the standard
                # output goes.


So, "scriptname.php >/dev/null 2>&1" says to redirect the standard output
of scriptname.php into the bit bucket and then to redirect the standard
error output to the same place.

-Dale
---------------------------------------------------
PLUG-discuss mailing list -
To subscribe, unsubscribe, or to change your mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss