Beruflich Dokumente
Kultur Dokumente
History
IO redirection
2
INVOKING BASH
On the command line:
% sh
3
STARTUP & SHUTDOWN FILES
/etc/profile
~/.bash_profile executed for login shell
~/.bash_login
/etc/bash.bashrc
executed for non-login shell
~/.bashrc
options:
--norc don’t run initialization files
-l run as login shell
4
~/.bash_logout
PREDEFINED SHELL VARIABLES
Shell Description
Variable
PWD The most recent current working directory.
5
USER-DEFINED SHELL VARIABLES
Syntax:
varname=value
let count=1
let count=$count+20
let count+=1
7
ARRAY VARIABLES
Syntax:
${varname[index]}
${varname[0]} first word in array
${varname[*]} all words in array
8
USING ARRAY VARIABLES
Examples:
9
EXPORTING VARIABLES
Environment variable is created by exporting
shell variable
10
VARIABLES COMMANDS
To delete both local and environment variables
unset varname
11
USING “SET” TO CHANGE OPTIONS
“set” is a builtin command of bash
“set +o” can be used to change an option
12
VARIABLE MANIPULATION
Example:
% SSN="123456789"
% password=${SSN:5:4}
% echo $password 13
% 6789
SPECIAL VARIABLE USES
${#variable}
number of characters in variable’s value
${varname:?message}
14
if variable is undefined display error “message”
BASH SHELL PROMPT
can be set via “PS1” shell variable
Secondary prompts:
PS2, PS3, PS4
15
BASH SHELL PROMPT
special “PS1” shell variable settings:
\w current work directory
\h hostname
Example:
% PS1="\u@\h-\!: "
ege@turing-22: 16
COMMAND HISTORY LIST
View or re-issue previously executed commands
Size of history can be set via shell variables:
19
REDIRECTION SYNTAX
Output:
> or 1> filename
Example:
% cat hugo > /tmp/one 2>&1
20
QUOTING
Quoting allows you to distinguish between the
literal value of a symbol and the symbols used as
code
21
A BACKSLASH (\)
A backslash is also called the escape character
It allows you to preserve only the character
For example:
to create a file named “tools>”, enter:
% touch tools\>
22
THE SINGLE QUOTE (‘)
A single quote is used to protect the literal
meaning of metacharacters.
Examples:
% echo "User $(whoami) is on $(hostname)"
User ege is on lx
% echo "Today is" `date`
Today is Sun Jul 17 08:06:28 CDT 2007
25
USING THE “EVAL” COMMAND
Evaluates a command line,
performs all shell substitutions, and then
26