onebeartoe.org - Programming Languages

Overview

Bash, also known as the Bourne again shell, is found on Unix and Linux operating systems.  It is used on the command line interface and in scripts saved as text files.

Variables

Variables can be set in Bash scripts with the assignment operator '=' and later used with the '$' character.  An example:

    echo $environment

    environment=development

    echo $environment
            

Output:


    development	
            

Redirection

Use the '>' redirection character to delete the contents of the file and output the previous command's sandard out to the file.

example:

ls > outfile.text

Use the '>>' rediection characters to append to the file.

example:

ls >> outfile.text

To append standard out and standard error to the same file redirect standard out like above and redirect standard error to the same file with 2>&1

example:

ls >> outfile.text 2>&1

A great explanation of this double redirection is in this StackOverflow answer.

Date Created: 2012-03-25 17:46:45 -0500 (Sun, 25 Mar 2012)





back    |    top