CATEGORII DOCUMENTE |
Asp | Autocad | C | Dot net | Excel | Fox pro | Html | Java |
Linux | Mathcad | Photoshop | Php | Sql | Visual studio | Windows | Xml |
The primary prompt ($PS1 - default $ or # for super-users) is displayed whenever the Bourne shell is ready to read a command. The secondary prompt ($PS2 - default >) is displayed when the Bourne shell needs more input.
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 command1 returns zero (successful) exit status |
command1 || command2 |
execute command2 if command1 returns non-zero (unsuccessful) exit status |
command |
continue command onto the next line |
execute command in the current shell |
|
command ) |
execute command in a subshell |
The Bourne shell provides a number of operators that can be used to manipulate command 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 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 |
n>file |
redirect file descriptor n to file |
n>>file |
redirect file descriptor n to file. Create file if non-existent, else overwrite. |
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 |
File name substitution is a feature which allows special characters and patterns to substituted with file 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, 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 |
Like in other high-level progamming languages, variables are used by the Bourne shell to store values. Variable names can begin with an alphabetic or underscore character, followed by one or more alphanumeric or underscore characters. 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 values can be accessed and manipulated using variable expansion. Basic expansion is done by preceding the variable name with the $ character. Other types of expansion use default or alternate values, assign default or alternate values, and more.
Variable Expansion Format
$variable |
value of variable |
value of variable |
|
value of variable if set and not null, else print word. If >5zWAmitted, variable is only checked if it is set. |
|
value of variable if set and not null, else variable is set to word, then expanded. If : is omitted, variable is only checked if it is set. |
|
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. |
|
value of variable
if set and not null, else print value of word and exit. If : is
omitted, variable is only chpOked if it is set:@$ |
Some special parameters are automatically set by the Bourne shell, and usually cannot be directly set or modified.
Special Parameters
$n |
positional parameter n |
number of positional parameters |
|
all positional parameters |
|
same as '$1' '$2' . . . '$n' |
|
same as '$1 $2 . . . $n' |
|
exit status of the last command |
|
process id of the current shell |
|
current options in effect |
|
process id of the last background command |
There are a number of variables provided by the Bourne shell that allow you to customize your working environment. Some are automatically set by the shell, some have a default value if not set, while others have no value unless specifically set.
Special Variables
CDPATH |
search path for cd when not given a full pathname; multiple pathnames are separated with a colon (no default) |
HOME |
default argument for the cd command; contains the pathname of the home directory |
IFS |
internal field separator (default space, tab, or newline) |
LANG |
contains the name of the current locale |
|
name of mail file to use if MAILPATH not set |
MAILCHECK |
specifies how often to check for mail in $MAIL or $MAILPATH. If set to 0, mail is checked before each prompt. (default 600 seconds) |
MAILPATH |
contains a list of colon-separated file names that are checked for mail. File names can be followed by a '%' and a message to display each time new mail is received in the mail file. (no default) |
PATH |
search path for commands; multiple pathnames are separated with a colon (default /bin:/usr/bin:) |
PS1 |
primary prompt string (default $, #) |
PS2 |
secondary prompt string (default >) |
SHACCT |
contains the name of the accounting file that contains accounting records for user shell procedures |
SHELL |
pathname of the shell |
TERM |
specifies your terminal type (no default) |
Quotes are used when assigning values containing whitespace or special characters, to delimit variables, and to assign command output. They also improve readability by separating arguments from commands.
remove the special meaning of enclosed characters except ' |
|
remove the special meaning of enclosed characters except $, ', and |
|
c |
remove the special meaning of character c |
`command` |
replace with the standard output of command |
Job control is a process manipulation feature found in the Bourne shell when invoked as jsh. It allows programs to be stopped and restarted, moved between the foreground and background, their processing status to be displayed, and more. When a program is run in the background, a job number and process id are returned.
Job Control Commands
bg [%n] |
put current or stopped job n in the background |
fg [%n] |
move current or background job n into foreground |
jobs |
display status of all jobs |
jobs -l |
display status of all jobs and their process ids |
jobs -p |
display process ids of all jobs |
jobs -x command |
replace job n in command with corresponding process group id, then execute command |
kill [-signal] %n |
send specified signal to job n (default 9) |
stop %n |
stop job n |
stty [-]tostop |
allow/prevent background jobs from generating output |
suspend |
suspend execution of current shell |
wait |
wait for all background jobs to complete |
wait %n |
wait for background job n to complete |
Ctl-z |
stop current job |
Job Name Format
current job |
|
%n |
job n |
previous job |
|
%string |
job whose name begins with string |
%?string |
job that matches part or all of string |
The Bourne shell has a number of options that specify your environment and control execution. They can be enabled/disabled with the set command or on the sh or jsh command line. Some options are only available on invocation.
Enabling/Disabling Options
sh [-/+options] |
enable/disable the specified options |
jsh [-/+options] |
enable/disable the specified options; enable job control (see JOB CONTROL section) |
set [-/+options] |
enable/disable the specified options (see also set) |
List of Options
-a |
automatically export variables that are defined |
-c commands |
read and execute commands (w/sh only) |
-e |
exit if a command fails |
-f |
disable file name expansion |
-h |
remember locations of functions on definition instead of on execution (see also hash) |
-i |
execute in interactive mode (w/sh only) |
-k |
put variable assignment arguments in environment |
-n |
read commands without executing them |
-p |
do not set effective ids to real ids |
-r |
run a restricted shell (w/sh only) |
-s |
read commands from standard input (w/sh only) |
-t |
exit after reading and executing one command |
-u |
return error on substitution of unset variables |
-v |
display input lines as they are read |
-x |
display commands and arguments as executed |
The test and [] commands are used to evaluate conditional expressions with file attributes, strings, and integers. The basic format is:
test expressionwhere expression is the condition you are evaluating. There must be whitespace after the opening bracket, and before the closing bracket. Whitespace must also separate the expression arguments and operators. If the expression evaluates to true, then a zero exit status is returned, otherwise the expression evaluates to false and a non-zero exit status is returned.
test File Operators
-b file |
true if file exists and is a block special file |
-c file |
true if file exists and is a character special file |
-d file |
true if file exists and is a directory |
-f file |
true if file exists is a regular file |
-g file |
true if file exists and its setgid bit is set |
-k file |
true if file exists and its sticky bit is set |
-L file |
true if file exists and is a symbolic link |
-p file |
true if file exists and is a fifo special file or a pipe |
-r file |
true if file exists and is readable |
-s file |
true if file exists and its size is greater than zero |
-S file |
true if file exists and is a socket |
-t n |
true if file descriptor n is open and associated with a terminal device |
-u file |
true if file exists and its set user-id bit is set |
-w file |
true if file exists and is writable |
-x file |
true if file exists and is executable |
Test String Operators
-n string |
true if length of string is not zero |
-z string |
true if length of string is zero |
string |
true if string is not set to null |
string1 = string2 |
true if string1 is equal to string2 |
string1 != string2 |
true if string1 is not equal to string2 |
string = pattern |
true if string matches pattern |
string != pattern |
true if string does not match pattern |
Test Integer Operators
exp1 -eq exp2 |
true if exp1 is equal to exp2 |
exp1 -ne exp2 |
true if exp1 is not equal to exp2 |
exp1 -le exp2 |
true if exp1 is less than or equal to exp2 |
exp1 -lt exp2 |
true if exp1 is less than exp2 |
exp1 -ge exp2 |
true if exp1 is greater than or equal to exp2 |
exp1 -gt exp2 |
true if exp1 is greater than exp2 |
Other test Operators
exp |
true if the given expression is false |
(exp) |
true if exp is true; used to group expressions ( used to escape parentheses) |
exp1 -a exp2 |
true if both exp1 and exp2 evaluate to true |
exp1 -o exp2 |
true if either exp1 or exp2 evaluate to true |
Execute commands associated with the pattern that matches value; patterns can contain the special filename substitution characters like *, ?, and []. Multiple patterns can be given but must be separated with a | character.
for variable in word1 word2 . . . wordnExecute commands once for each word, setting variable to successive words each time.
for variableExecute commands once for each positional parameter, setting variable to successive positional parameters each time.
if command1Execute commands if command1 returns a zero exit status.
if command1Execute commands2 if commands1 returns a zero exit status, otherwise execute commands3.
if command1If command1 returns a zero exit status, or command2 returns a zero exit status, or commandn returns a zero exit status, then execute the commands corresponding to the if/elif that returned a zeroexit status. Otherwise, if all the if/elif commands return a non-zeroexit status, execute the commands between else and fi.
until command1Execute commands until command1 returns a zero exit status
while command1Execute commands while command1 returns a zero exit status.
null command; returns zero exit status |
||
file |
read and execute commands from file in current environment |
|
begin comments; terminate with a newline |
||
break |
exit from current for, until, or while loop |
|
break n |
exit from nth enclosing for, until, or while loop |
|
cd dir |
change directory to dir. If dir not specified, change directory to $HOME. |
|
echo args |
display args |
|
eval command |
evaluate command and execute the result |
|
exec command |
replace current process with command |
|
exit |
exit from the current program with the exit status of the last command. If given at the command prompt, terminate the login shell. |
|
exit n |
exit from the current program with exit status n |
|
export |
display a list of exported variables |
|
export var |
export variable var |
|
getopts |
parse positional parameters and options |
|
hash |
display a list of hashed commands |
|
hash commands |
remember locations of commands by putting them in the hash table |
|
hash -r |
remove all commands from the hash table |
|
hash -r command |
remove command from the hash table |
|
newgrp |
change the group-id to the default group-id |
|
newgrp gid |
change group id to gid |
|
pwd |
display the pathname of the current directory |
|
read variables |
read a line from standard input; assign each word on the line to each variable. Words delimited with $IFS. |
|
readonly |
display a list of readonly variables |
|
readonly var |
set variable var to be readonly |
|
return |
exit from a function with return status of the last command |
|
return n |
exit from a function with return status n |
|
set |
display a list of current variables and their values |
|
set args |
set positional parameters to args |
|
set -args |
set positional parameters that begin with - |
|
set [options ] |
enable/disable options (see OPTIONS section) |
|
shift |
shift positional parameters once to the left |
|
shift n |
shift positional parameters n times to the left |
|
test expression |
evaluate expression (see CONDITIONAL EXPRESSIONS section) |
|
times |
display total user and system time for current shell and its child processes |
|
trap |
display list of current traps |
|
trap commands signals |
execute commands when signals are received |
|
trap '' signals |
ignore signals |
|
trap signals, trap -signals |
reset traps to their default values |
|
trap commands 0 |
execute commands on exit from the shell |
|
type command |
display information and location for command |
|
ulimit [type] [options] n |
set a resource limit to n. If n is not given, the specified resource limit is displayed. If no option is given, the file size limit (-f) is displayed. If no type is given, both limits are set, or the soft limit is displayed; type can be: |
|
H |
hard limit |
|
-S |
soft limit |
|
and options can be: |
||
-a |
displays all current resource limits |
|
-c n |
set core dump size limit to n 512-byte blocks |
|
-d n |
set data area size limit to n kilobytes |
|
-f n |
set child process file write limit to n 512-byte blocks (default) |
|
-m n |
set physical memory size limit to n kilobytes |
|
-s n |
set stack area size limit to n kilobytes |
|
-t n |
set process time limit to n seconds |
|
-vn |
set virtual memory size to n kilobytes |
|
umask |
display current file creation mask value |
|
umask mask |
set default file creation mask to octal mask |
|
unset variable |
remove definition of variable |
|
wait [n] |
wait for execution (see JOB CONTROL section) |
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()
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.
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'.
$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. |
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 |
[a-c] |
any character in range a through c |
[^abc] |
any character except a, b, or c |
[^a-c] |
any character except characters in a-c |
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) |
The following commands are frequently used in Bourne shell scripts to filter input and output.
Pattern Scanning and Processing Language
$awk [ options ] [ 'program' ] [ parameters ] [ 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 |
Program Format:
Patterns in program can be associated with a statement to perform if an input line matches the pattern. The format is:
patternA missing pattern always matches, and a missing statement prints the current input line.
Patterns:
BEGIN |
match before first input line |
END |
match after last input line |
pattern1, pattern2, , patternn |
match if pattern1, pattern2, or patternn match current input line |
pattern1 && pattern2 |
match if pattern1 and pattern2 match current input line |
pattern1 || pattern2 |
match if pattern1 or pattern2 match current input line |
!pattern |
match if pattern does not match current input line |
/regular-expression/ |
match if regular-expression matches current input line |
relational-expression |
match if relational-expression evaluates to true |
Flow Control Statements:
break |
exit from a for or while loop |
continue |
execute next for or while loop |
delete variable[expression] |
delete element expression from array variable |
do statement while (expression) |
execute statement while expression is true |
exit |
skip remaining input |
for (expression1 expression2; expression3) statement |
execute statement while expression2 is true; loop is usually initialized with expression1 and incremented with expression3 |
for (variable in array) statement |
execute statement, setting variable to successive elements in array |
if (expression statement1 [ else statement2 ] |
execute statement1 if expression is true, otherwise execute statement2 |
next |
skip rest of the input line |
return[expression] |
return value of expression |
system(command |
execute command and return status |
while (expression statement |
execute statement while expression is true |
Input/Output Statements:
close(file) |
close file |
getline |
set $0 to next input record; set NF, NR, FNR |
getline<file |
set $0 to next input from file; set NF |
getline var |
set var to next input record; set NR, FNR |
getline variable<file |
set variable to next input record from file |
command | getline |
pipe output of command into getline |
|
print current input record |
print expression |
print expression; multiple expressions must be separated with a ',' |
print expression>file |
print expression to file; multiple expressions must be separated with a ',' |
printf format expression |
print expression according to C-like format. Multiple expressions must be separated with a ','. Output can also be appended to file using >> or piped to a command using |. |
printf format expression>file |
print expression to file according to C-like format. Multiple expressions must be separated with a ','. Output can also be appended to file using >> or piped to a command using |. |
Functions:
atan2(x,y) |
arctangent of x/y in radians |
cos(expr) |
cosine of expr |
exp(expr) |
exponential of expr |
gsub(regular-expression, string1, string2) |
substitute string1 for all instances of regular-expression in string2. If string2 is not specified, use the current record $0. |
index(string1, string2) |
return the position of string1 in string2 |
int(expr) |
integer value of expr |
length(string) |
return the length of string |
log(expr) |
natural logarithm of expr |
match(string, regular-expression) |
return the position in string where regular-expression occurs. If not found, return 0. RSTART is set to starting position, and RLENGTH is set to the length of string. |
rand |
random number between 0 and 1 |
sin(expr) |
sine of expr in radians |
split(string, array) |
split string into array using $FS |
split(string, array, fs) |
split string into array using fs as separator |
sprintf(format, expr) |
format expr according to the printf format |
sqrt(expr) |
square root of expr |
srand |
new seed for rand (current time) |
srand(expr) |
set the seed for rand to expr |
sub(regular-expression, string1, string2) |
substitute string1 for the first instance of regular-expression in string2. If string2 not specified, use the current record $0. |
substr(string, x) |
return the suffix of string starting at position x |
substr(string, x, n) |
return n character substring of string starting at position x |
function name(args,) | |
func name(args,) name (expr, expr, . . .) |
define a function name |
Operators:
assignment operators |
|
conditional expression |
|
||, &&, ! |
logical OR, logical AND, logical NOT |
regular expression match/do not match |
|
<, <=, >, >=, !=, == |
relational operators |
add, subtract |
|
multiple, divide, modulo |
|
unary plus, unary minus |
|
exponentiation |
|
increment, decrement |
Variables:
$ARGC |
number of command-line arguments |
$ARGV |
array of command-line arguments |
$FILENAME |
current input file |
$FNR |
record number in current input file |
$FS |
input field separator (default blank and tab) |
$NF |
number of fields in the current record |
$NR |
number of current record |
$OFMT |
output format for numbers (default %g) |
$OFS |
output field separator (default blank) |
$ORS |
output record separator (default newline) |
$RLENGTH |
length of string matched by match() |
$RS |
contains the input record separator (default newline) |
$RSTART |
index of first character matched by match() |
$SUBSEP |
subscript separator (default 034) |
current input record |
|
n |
nth input field of current record |
Display File Fields
$cut -clist [ files ]Description:
The cut command displays fields from lines in the specified files according to selection options. The fields can be of fixed or variable length.
Options:
-clist |
display characters from the positions in list |
-dc |
set the field delimiter to c (default tab) |
-flist |
display the fields specified in list |
-s |
suppress lines with no delimiter characters |
files |
read standard input if files are -, or no files are specified |
list |
comma separated list of integer field numbers; integers separated with a - indicate a range |
Display Arguments
$echo argumentsDescription:
The echo command displays arguments on standard output. Special escape characters can be used to format arguments.
Escape Characters:
b |
backspace |
c |
line without ending newline |
f |
formfeed |
n |
newline |
r |
carriage return |
t |
tab |
v |
vertical tab |
backslash |
|
x |
character whose octal value is x |
Search Files for Patterns
$egrep [ options ] 'expression' [ files ]Description:
The egrep command displays lines in files that contain the given full regular expression pattern.
Options:
-b |
precede each line with the block number |
-c |
display the number of lines that match only |
-e -expression |
search for expression that begins with - |
-f file |
get expressions from file |
-i |
ignore case of letters during comparisons |
-l |
display file names with matching lines once |
-n |
display the output with line numbers |
-v |
display non-matching lines |
files |
read standard input if no files are specified |
Evaluate Expression Arguments
$expr argumentsDescription:
The expr command evaluates arguments as an expression. Expression tokens must be separated with blanks, and special characters must be escaped. Integer arguments can be preceded by a minus sign to indicate a negative number.
Operators (listed in order of precedence):
exp1 | exp2 |
return exp1 if neither null nor 0, else return exp2 |
exp1 & exp2 |
return exp1 if neither null nor 0, else return 0 |
exp1 <, <=, =, !=, >=, > exp2 |
return result of the integer or string comparison |
exp1 +, -, *, /, % exp2 |
return result of the arithmetic operation |
exp1 : exp2 |
return the result on the number of matched characters between exp1 and exp2 |
Search Files for Patterns
$grep [ options ] 'expression' [ files ]Description:
The grep command displays lines from files that match the given limited regular expression.
Options:
-b |
precede each line with the block number |
-c |
display the number of matching lines |
-i |
ignore case of letters during comparisons |
-l |
display only filenames with matching lines once |
-n |
display the output with line numbers |
-s |
do not display error messages |
-v |
display non-matching lines only |
files |
read standard input if no files are specified |
Merge Lines Between Files
$paste file1 file2 . . .Description:
The paste command merges corresponding lines from files. Each file is treated as a column or columns of a table and displayed horizontally.
Options:
-dlist |
replace tabs with characters from list. If this option is not specified, the newline characters for each file (except for the last file, or if -s is given, the last line) are replaced with tabs. The list can contain these special characters: |
||
n |
newline |
||
t |
tab |
||
empty string |
|||
backslash |
|||
-s |
merge subsequent lines instead of one |
||
files |
read standard input if file1 or file2 is - |
Stream Editor
$sed [ -n ] [ -e 'script ' [ -f file ] [ files ]Description:
The sed command copies files to standard output and edits them according to the given editing commands.
Options:
-e script |
execute commands in script |
-f file |
get commands from file |
-n |
suppress default output |
files |
read standard input if no files given |
Command Format:
[address [ ,address ] ] commands [ arguments ]execute commands for each input line that matches address or range of addresses. If commands is preceded by '!', input lines that do not match the address are used.
Addresses:
If no address is given, all input lines are matched.
Two addresses indicate a range.
current line |
|
last line |
|
n |
nth line |
/regular-expression |
regular expression |
n |
newline |
Commands:
The maximum number of addresses listed in parentheses.
(1)a |
append the following text to the output text |
|
(2)b label |
branch to the :label command. If label is empty, go to the end of the script. |
|
(2)c |
change line text |
|
(2)d |
delete lines |
|
(2)D |
delete first line of input only |
|
(2)g |
replace input lines with buffer contents |
|
(2)G |
append buffer contents to input lines |
|
(2)h |
replace buffer contents with input lines |
|
(2)H |
append input lines to buffer contents |
|
(1)i |
insert the following text text |
|
(2)l |
display input lines |
|
(2)n |
display input line; read next input line |
|
(2)N |
append next input line to current line |
|
(2)p |
display input lines |
|
(2)P |
display first line of input line only |
|
(1)q |
quit |
|
(2)r file |
display contents of file |
|
(2)s/RE/s/flags |
substitute s for the regular expression RE that matches input lines according to flags. The flags can consist of zero or more of: |
|
n |
substitute for just the nth occurrence of the regular expression RE (1-512) |
|
g |
substitute for all occurrences of RE |
|
p |
display input line if substitution was made |
|
w file |
append input line to file if substitution made |
|
(2)t label |
branch to :label command if substitution was made. If label is empty, go to end of script. |
|
(2)w file |
append input line to file |
|
(2)x |
exchange input line with buffer contents |
|
(2)y/s1/s2 |
replace characters in s1 with characters in s2. The lengths of s1 and s2 must be equal. |
|
(2)!cmd |
execute command for the input lines not selected |
|
display current line number |
||
(2) as a group |
||
interpret rest of input line as comments |
||
(0)#n |
interpret rest of input line as comments and ignore |
Sort-Merge Files
$sort [-cmu] [-ofile] [-yk] [-zn][-dfiMnr][-btc]Description:
The sort command sorts lines from files.
Options:
-b |
ignore leading tabs and spaces |
|
-c |
check that the input is in sorted order |
|
-d |
sort in dictionary order; only letters, digits, and white-space are significant in comparisons |
|
-f |
sort upper and lower case letters together |
|
-i |
ignore non-printable characters |
|
-m |
merge already sorted files |
|
-M |
sort as months. The first three non-blank characters are converted to upper case and compared. (implies -b) |
|
-n |
sort by numerical value; blanks, minus signs, and decimal points can also be given (implies -b) |
|
-ofile |
send output to file (default standard output) |
|
-r |
reverse the sorting order |
|
-tc |
set the field separator to c |
|
-u |
display only one occurrence of duplicate lines |
|
-y[k] |
use k kilobytes of memory to sort (default max) |
|
-zn |
use n bytes of buffer for long lines |
|
files |
read standard input if files is - or no files given |
|
+pos1 [ -pos2] sort from pos1 to pos2. |
||
If pos2 is not specified, sort from pos1 to the end of line. The format for pos1 and pos2 is: m[.n] [bdfinr] |
||
m |
m fields from start of line (default 0) |
|
n |
n characters from start of field (default 0) |
|
bdfinr |
option applies to the specified key only |
Translate Characters
$tr [-cds] [string1] [string2]Description:
The tr command copies standard input to output and translates characters from string1 to characters in string2.
Options:
-c |
translate characters not in string1 |
-d |
delete characters in string1 from input |
-s |
truncate repeated characters from string2 |
Strings:
[a-z] |
specifies range of characters from a to z |
[c*n] |
specifies n repetitions of c. If the first digit in n is 0, n interpreted as octal. (default decimal) |
Report Duplicate Lines
$uniq [ -udc [ +n ] [ -n ] ] [ file1 [ file2 ] ]Description:
The uniq command removes duplicate adjacent lines from file1 and places the output in file2.
Options:
-c |
display a count of duplicate lines also |
-d |
display only duplicate lines once |
-u |
display only unique lines from the original file |
n |
skip first n fields from start of line |
+n |
skip first n characters from the start of field |
Count Characters, Lines and Words
$wc [ -clw ] [ files ]Description:
The wc command counts the characters, lines, or words in the specified files. A total count for all files is kept.
Options:
-c |
display number of characters (default all options) |
-l |
display number of lines |
-w |
display number of words |
files |
read standard input if no files are specified |
The bnl script is the Bourne shell version of the UNIX nl command. It displays line-numbered output.
#!/bin/shThe kcal script implements a menu-driven calendar program. It supports addition, deletion, modification, and listing of calendar entries. It also provides the ability to find the calendar entry for the current day and list all calendar entries.
#!/bin/sh
Politica de confidentialitate | Termeni si conditii de utilizare |
Vizualizari: 1407
Importanta:
Termeni si conditii de utilizare | Contact
© SCRIGROUP 2024 . All rights reserved