|
Bash Configuration |
Type of Shell |
Function |
|
~/.bashrc |
Non-login shells (Although login shells on most |
Stores individual user’s shell preferences. |
|
/etc/profile |
Login shells |
Contains configuration parameters that are applied |
|
~/.bash_profile |
Login shells |
Stores individual users’ shell preferences |
|
~/.bash_login |
Login shells |
Stores individual users’ shell preferences |
|
~/.profile |
Login shells |
Stores individual users’ shell preferences |
|
~/bash_logout |
Login shells |
Specifies actions to be performed when a user logs out |
Commonly Used
Environment Variables
|
Environment |
Stores |
Default Values |
|
BASH and SHELL |
The full path to the shell executable |
/bin/bash |
|
CPU |
The type of CPU installed in the system |
Depends on your system. An Intel Pentium IV computer would |
|
DISPLAY |
The location where your X Windows display should be sent |
0.0 (the local video card and monitor) |
|
ENV |
The name of the file bash read to configure its |
~/.bashrc |
|
EUID |
The user ID (UID) of the current user |
The UID number of the current user |
|
HISTFILE |
The path to the bash command history file |
~/.bash_history |
|
HISTSIZE |
The number of commands saved in the command history |
1000 |
|
HOME |
The path to the current user’s home directory |
The current user’s home directory. |
|
HOST and HOSTNAME |
The hostname of the system |
The hostname you assigned when you installed the system |
|
INFODIR |
The path to your system’s info program |
/usr/local/info:/usr/share/info:/usr/info |
|
LOGNAME |
The username of the current user |
The username of the current user |
|
|
The path to the current user’s mailbox file |
/var/spool/mail/username |
|
MANPATH |
The path to your system’s man program |
/usr/local/man:/usr/share/man:/usr/X11R6/man:/opt/gnome/share/man |
|
OLDPWD |
The path to the prior current directory |
Depends on what your prior current directory was |
|
OSTYPE |
The type of operating system currently running |
Linux |
|
PATH |
A list of directories to be searched when running a |
Depends on your distribution |
|
PS1 |
The characters used to create the shell prompt |
Depends on your distribution |
|
PWD |
The path to the current working directory |
Depends on what your current directory is |
You can use the set command
to view all your variables in a linux system. You can also use the env command to see your system
environment variables.
You must type export
VARIABLE to use a new or changes variable on a new shell.
File descriptors:
Stdin – This file
descriptor stands for standard input. Standard input is the input provided to a
particular command to process. The stdin for a command is represented by the
number 0.
Stdout – This
file descriptor stands for standard output. Standard output is simply the
output from a particular command. For example, the directory listing generated
by the ls command is its stdout. The stdout for a command is represented by the
number 1.
Stderr – This
file descriptor stands for standard error. Standard error is the error code
generated, if any, by a command. The stderr for a command is represented by the
number 2.
Cat file > output
- will save stdout ( no errors )
Cat file 1> output
- will save stdout ( no errors )
Cat file 2> output - will save stderr ( ERRORS )
Cat file 1> output
2>&1 - This will put both stdout and stderr in the same file.
Cat file 1>>
output 2>&1 - This will output both stdout and stderr to the same
file.
Sed Commands
s – Replaces
instances of a specified text string with another text string. The syntax for
using the s command is sed
s/term1/term2/.
d – Deletes the
specified text. For example, to delete every line of text from the stdin that
contains the term “eos”, you would enter sed
/eos/d.
AWK character outputs
t - Inserts a
tab character
n - Adds a new
line character.
f - Adds a
formfeed character.
r - Adds a
carrieage return character.
Shell Scripts
All variables are interpreted as text unless defined
otherwise. To declare a variable to be an integer use the following code: declare -i VAR.
If/Then/Else
statement structure:
If condition then
Commands
Else
Commands
Fi
Check if a directory/file exists.
If [ -e $VAR ]; then
Echo “exists”;
Fi
Case Syntax
Case variable in
Response_1
) commands
;;
Response_2
) commands
;;
Response_3
) commands
;;
Esac
Example:
Read NAME
Case $NAME in
Tully )
echo “Your name is Tully!”
;;
Tullyr )
echo “Awesome Tullyr!”
;;
Rankin )
echo “You have my last name!”
;;
* ) echo
“Your name is not cool”
;;
Esace
Exit0
While Loops
While condition
Do
Script
commands
Done
Until loop
Until condition
Do
Script
commands
Done