Bourne Shell Quick Reference Guide:
Previous
Table of Contents
Next
FUNCTIONS
Functions are used to reference a group of commands with a single name. They are more efficient to use than equivalent Bourne shell scripts, because once a function has been defined, it doesn't have to be read in from the disk again. Functions also provide a way to organize Bourne shell scripts into routines, like in other high-level programming languages. To be used, functions must be read in first, but can then be invoked like regular commands. For example, in Bourne shell scripts, functions are included at the top so that they are read in first. Environment functions can be put into a file and read in with the . command. Functions cannot be exported, so they are only available to the current shell. To exit from a function, but not from a Bourne shell script, use the return command. Functions are defined with the following format: name() { commands ; }
RESTRICTED SHELL
Running under the restricted shell rsh is equivalent to sh, except that changing directories, setting the value of PATH, specifying path or command names containing /, and redirecting output with > or >> are not allowed.
DEBUGGING BOURNE SHELL SCRIPTS
The Bourne shell provides a number of options that are useful in debugging scripts: n, v, and x. The n option causes commands to be read without being executed and is used to check for syntax errors. The v option causes the input to displayed as it is read. The x option causes commands in Bourne shell scripts to be displayed as they are executed. This is the most useful, general debugging option. For example, tscript could be run in trace mode if invoked "sh x tscript".
FILES
$HOME/.profile
contains local environment settings. At login time, it is read in and executed after the /etc/profile file.
/etc/profile
contains system-wide environment settings. If existent, it is read in and executed before $HOME/.profile.
REGULAR EXPRESSIONS
c
non-special character c
\c
special character c
^
beginning of line
$
end of line
.
any single character
[abc]
any character a, b, or c
[ac]
any character in range a through c
[^abc]
any character except a, b, or c
[^ac]
any character except characters in ac
\n
nth \(...\) match (grep only)
rexp*
zero or more occurrences of rexp
rexp+
one or more occurrences of rexp
rexp?
zero or one occurrence of rexp
rexp1 | rexp2
regular expressions rexp1 or rexp2
\(rexp\)
tagged regular expression rexp (grep)
(rexp)
regular expression rexp (egrep)
MISC COMMANDS
The following commands are frequently used in Bourne shell scripts to filter input and output.
awk/nawk
Pattern Scanning and Processing Language
$awk [ options ] [ 'program' ] [ parameters ] [ files ]
$nawk [ options ] [ 'program' ] [ files ]
Description:
The awk/nawk command performs actions for lines in files that match patterns specified in program. Each input line is made up of fields separated by whitespace.
Options:
ffile
get patterns from file instead of program
Fc
separate fields with character c (default whitespace)
v variable=value
assign value to variable (nawk only)
parameters
parameters have the format variable=expression
files
read standard input if files is or no files are specified
Previous
Table of Contents
Next
Wyszukiwarka
Podobne podstrony:
015 018pagon 018v 01 015018 Flm018 19018 13 (2)I B 015więcej podobnych podstron