Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Download
Standard view
Full view
of .
Look up keyword
Like this
17Activity
0 of .
Results for:
No results containing your search query
P. 1
68 Bash Shell Reference

68 Bash Shell Reference

Ratings:

4.67

(1)
|Views: 1,152|Likes:
Published by michelbisson
Bash Shell Reference Manual
Bash Shell Reference Manual

More info:

Published by: michelbisson on Dec 26, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

10/29/2012

pdf

text

original

 
Linux-Kurs Themen Bash Shell Reference- Feb 5, 2006Michel Bisson
Table of Contents
COMMAND EXECUTION.....................................................................................................2
FILENAME SUBSTITUTION........................................................................................................................3
VARIABLES...........................................................................................................................3VARIABLE SUBSTITUTION..................................................................................................3SPECIAL PARAMETERS......................................................................................................4SPECIAL VARIABLES...........................................................................................................4JOB CONTROL.....................................................................................................................5QUOTING..............................................................................................................................6OPTIONS..............................................................................................................................6
Enabling/Disabling Options...........................................................................................................................6
CONDITIONAL EXPRESSIONS............................................................................................7CONDITIONAL CONTROL COMMANDS...........................................................................10BUILTIN COMMANDS........................................................................................................13RESTRICTED SHELL........................................................................................................14DEBUGGING BOURNE SHELL SCRIPTS.......................................................................14FUNCTIONS........................................................................................................................15ALIASES..............................................................................................................................15COMMAND SEARCH PRIORITY......................................................................................16FILES...................................................................................................................................16SET and UNSET commands...............................................................................................17REGULAR EXPRESSIONS.................................................................................................17echo COMMAND:................................................................................................................18PROMPT MANIPULATION.................................................................................................18Job control (disown) Exercise: ...........................................................................................19Bash session recording:......................................................................................................19Monitoring a bash session from one or more users:...........................................................19Bash options:.......................................................................................................................20Command History and command line editing:.....................................................................21EXAMPLE COMMANDS......................................................................................................22
68_Bash_Shell_Reference.sxw -
1
 
Linux-Kurs Themen Bash Shell Reference- Feb 5, 2006Michel Bisson
COMMAND EXECUTION
The primary prompt (
$
PS1
- default
$
or 
#
for super-users) is displayed whenever theBourne shell is ready to read a command.The secondary prompt (
$
PS2
-
default
 
>
) is displayed when the command is incomplete.
Command Execution Format
command1
 
;
 
command2
 
execute
 
command1
 
followed by
command2
 
command 
&
execute
 
command 
 
asynchronously
 
in
 
the
 
background
 
command1
|
command2
 
pass
 
the
 
standard
 
output
 
of 
 
command1
to
standard
 
input
 
of 
command2
 
command1
&&
command2
execute
 
command2
 
if 
 
and
 
only
 
if 
 
command1
 
returns
 
zero(successful)
 
exit
 
statuseg.
/sbin/lsmod | grep -q ^ipw2200 && { rmmod ipw2200; modprobe ipw2200; }
command1
||
command2
execute
 
command2
 
if and only if 
 
command1
r
eturns non-zero(unsuccessful) exit status
command 
\
continue
 
command 
 
onto the next line. '\' must be the last char 
.
if {
command 
 
; }
 
execute
 
command 
 
in the current shell.eg
.
if { cat /etc/motd &>/dev/null ; } ; then
if (
command 
)
 
execute
 
command 
 
in a subshell.eg.
if (cat /etc/motd &>/dev/null) ; then
REDIRECTING INPUT/OUTPUT
The Bourne shell provides a number of operators that can be used to manipulatecommand input/output, and files.
I/O Redirection Operators
<
file
 
redirect standard input from
file
 
>
file
 
redirect standard output to
file
. Create
file
if non-existent, else overwrite.
>>
file
 
append standard output to
file
; Create
file
if non-existent.
<&
-
 
close standard input
>&
-
 
close standard output
<&
n
 
redirect standard input from file descriptor 
n
 
>&
n
 
redirect standard output to file descriptor 
 
n
 
n
<
file
 
redirect file descriptor 
n
from
file
 
&
>file
redirect file both
stdout(1)
and
stderr(2)
file descriptors to
filen
>
file
 
redirect file descriptor 
n
to
file
.
Create
file
 
if non-existent, else overwrite
.
n
>>
file
 
redirect file descriptor 
n
to
file
. Create
file
if non-existent.
n
<&
m
 
redirect file descriptor 
n
from file descriptor 
m
 
n
>&
m
 
redirect file descriptor 
n
to file descriptor 
m
 
n
<<
x
 
redirect to file descriptor 
n
until
x
is read
n
<<
-
x
 
same as
n
<<
x
, except ignore leading tabs
n
<&
-
 
close file descriptor 
n
for standard input
n
>&
-
 
close file descriptor 
n
for standard output
&>
n
redirect standard output and standard error to file descriptor 
n
 
68_Bash_Shell_Reference.sxw -
2
 
Linux-Kurs Themen Bash Shell Reference- Feb 5, 2006Michel Bisson
FILENAME SUBSTITUTION
File name substitution is a feature which allows special characters and patterns to substituted withfile names in the current directory, or arguments to the
case
and
test
commands.
Pattern-Matching Characters/Patterns
?
 
match any single character 
*
match zero or more characters, including null
[
abc
]
match any characters between the brackets
[
x-z
]
match any characters in the range
 
x
 
to
 
z
 
[
a-ce-g
]
match any characters in the range
 
a
 
to
c
 
or 
 
e
 
to
 
g
 
[
!abc
]
match any characters not between the brackets
[
!x-z
]
match any characters not in the range
 
x
 
to
 
z
 
.
 
strings starting with
 
.
 
must be explicitly matched
VARIABLES
Variables are used by the Bourne shell to store values. Variable names can begin with analphabetic or underscore character, followed by one or more alphanumeric or underscorecharacters. Other variable names that contain only digits or special characters are reserved for special variables (called
 parameters
) set directly by the Bourne shell.
Variable Assignment Format
variable
=,
variable
=""
declare
 
variable
 
and set it to null
variable
=
value
 
assign
 
value
 
to
 
variable
 
variable
=
value
 
command 
Set the variable with value and run the command
VARIABLE SUBSTITUTION
Variable values can be accessed and manipulated using variable expansion. Basic expansion isdone by preceding the variable name with the
 
$
 
character 
.
Other types of expansion use defaultor alternate values, assign default or alternate values, and more.
Variable Expansion Format
$
variable
 
value of 
variable
 
${
variable
}
value of 
variable
 
${#
variable
}
numeric length(number of chars.) of value of 
 
variable
${
variable
:-
word 
}
value of 
variable
if set and not null, else print
word 
.
If 
 
:
 
is omitted,
 
variable
 
is only checked if it is set.eg.
echo ${USER:-halo} ; echo $USER${
variable
:+
word 
}
value of 
 
word 
i
 
variable
 
is set and not null, else nothing issubstituted. If 
:
is omitted,
 
variable
 
is only checked if it is set.eg.
 
echo ${USER:+halo} ; echo $USER
${
variable
:=
word 
}
value of 
 
variable
i
f set and not null, else variable is set to
 
word 
,then expanded. If 
:
is omitted,
 
variable
 
is only checked if it is set.
${
variable
:?}
value of 
variable
if set and not null, else print "
variable: parameter null or not set
". If 
:
 
is omitted,
variable
is only checked if it is set.
 
${
variable
:?
word 
}
value of 
variable
if set and not null, else print value of 
word 
andexit. If 
:
is omitted,
variable
 
is only checked if it is set.
68_Bash_Shell_Reference.sxw -
3

Activity (17)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
Tjako1 liked this
Tjako1 liked this
crazpiyush liked this
isi_007 liked this
kilaz liked this
Satish Reddy liked this
juliartojosefus liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->