Using Aliases; Using Variables In Bash - Novell LINUX ENTERPRISE SERVER 11 - ADMINISTRATION Administration Manual

Hide thumbs Also See for LINUX ENTERPRISE SERVER 11 - ADMINISTRATION:
Table of Contents

Advertisement

acter. For example, the following line searches for a file starting with foo, but suppresses
its errors by redirecting it to /dev/null:
find / -name "foo*" 2>/dev/null

5.4 Using Aliases

An alias is a shortcut definition of one or more commands. The syntax for an alias is:
alias NAME=DEFINITION
For example, the following line defines an alias lt which outputs a long listing (option
-l), sorts it by modification time (-t) and prints it in reverse order while sorting (-r):
alias lt='ls -ltr'
To view all alias definitions, use alias.

5.5 Using Variables in Bash

A shell variable can be global or local. Global variables, or environment variables, can
be accessed in all shells. In contrast, local variables are visible in the current shell only.
To view all environment variables, use the printenv command. If you need a special
variable, insert the name of your variable as an argument:
printenv PATH
A variable can also be viewed with echo:
echo $PATH
This prints the PATH variable. To set a local variable, use a variable name followed by
the equal sign, followed by the value:
PROJECT="SLED"
Do not insert spaces around the equal sign, otherwise you get an error. To set a environ-
ment variable, use export:
export NAME="tux"
Bash and Bash Scripts
47

Advertisement

Table of Contents
loading

This manual is also suitable for:

Suse linux enterprise server 11

Table of Contents