Linux First Steps
computer software
Linux First Steps Linux First Steps
Linux First Steps   Home | Site Map | About Us | Products | Services | News | Contact Us | Links Linux First Steps
Linux First Steps Linux First Steps

Copyright © 2009

Linux® Bible


existing beneath a point you choose in the file system. (In other words, don't use
grep a
from the
root file system or you'll match and try to edit several thousand files.)
Expanding Arithmetic Expressions
There may be times when you want to pass arithmetic results to a command. There are two forms
you can use to expand an arithmetic expression and pass it to the shell:
$[expression]
and
$(expression)
. Here is an example:
$ echo "I am $[2008 - 1957] years old."
I am 51 years old.
The shell interprets the arithmetic expression first (
2008 - 1957
), and then passes that informa-
tion to the
echo
command. The
echo
command displays the text, with the results of the arith-
metic (
51
) inserted.
Here's an example of the other form:
$ echo "There are $(ls | wc -w) files in this directory."
There are 14 files in this directory.
This lists the contents of the current directory (
ls
) and runs the word count command to count
the number of files found (
wc -w
). The resulting number (14 in this case) is echoed back with the
rest of the sentence shown.
Expanding Environment Variables
Environment variables that store information within the shell can be expanded using the dollar
sign (
$
) metacharacter. When you expand an environment variable on a command line, the value
of the variable is printed instead of the variable name itself, as follows:
$ ls -l $BASH
-rwxr-xr-x 1 root root 625516 Dec 5 11:13 /bin/bash
Using
$BASH
as an argument to
ls -l
causes a long listing of the bash command to be printed.
The following section discusses shell environment variables.
Creating Your Shell Environment
You can tune your shell to help you work more efficiently. Your prompt can provide pertinent
information each time you press Enter. You can set aliases to save your keystrokes and permanently
set environment variables to suit your needs. To make each change occur when you start a shell,
add this information to your shell configuration files.
Configuring Your Shell
Several configuration files support how your shell behaves. Some of the files are executed for
every user and every shell, while others are specific to the user who creates the configuration file.
Table 2-5 shows the files that are of interest to anyone using the bash shell in Linux.
56
Linux First Steps
Part I