2011年10月21日星期五

UGG Online Outlet Note shell Quick Document

note: shell Quick documentation 2011-04-20 12:51 First, users log into the system after the system environment variables:
$ HOME user's own directory
$ PATH search when executing the command catalog
$ TZ time zone
$ MAILCHECK number of seconds to check every new letter
$ PS1 prompt in the command line when No.
$ PS2 when the command has not kick when, Shell request to re- Tips input number
$ MANPATH man command search path
two special variables:
$ 0 the name of the program's implementation of this program
$ n the n th parameter values, n = 1.9 < br> $ * this program all the parameters
$ # number of parameters of this process
$ $ of this process PID
$! Execute a command on the PID
$? Execute a command on the return value of three,UGG Online Outlet, shell of the argument:
* any string
? An arbitrary character
[abc] a, b, c one of the three in
[an] n from a to any one character
four, a few special characters that
b back
c print line without line breaks that we often will be used
f form feed
r carriage return
t tab
v vertical tab
backslash
five, to determine the properties of the file
format: - operator filename
-e file exists return 1, otherwise it returns 0
-r file read returns 1, otherwise it returns 0
-w file is writable returns 1, otherwise 0
-x file is executable returns 1, otherwise it returns 0
-o file is the user himself to return 1, otherwise it returns 0
-z file length of 0 returns 1, otherwise it returns 0.
-f file a regular file returns 1, otherwise it returns 0
-d File is a directory file, returns 1, otherwise it returns 0
six test string
string 1 = string 2 when the two strings are equal When a string is true
1! String = string 2 when two unequal true
-n string when the string length is greater than zero is true
-z string when the string length of 0 is true < br> string when the string is non-empty string is true
seven test the relationship
two integer numbers 1-eq equal to the number two number 2 is true
digital 2 digital 1-ne number two does not so true
number 1-gt is greater than the number 1 number 2 number 2 is true
number 1-ge greater than or equal the number 1 number 2 number 2 is true
number 1-lt 1 number 2 number of small in figure 2 is true
number 1-le less than or equal the number 1 number 2 number 2 is true
eight logic test
-a and
-o or
! Non-
shell special characters, today introduced a reference
===
shell special characters in there
1, $ dollar sign
2, backslash
3, `anti- quotes
4, is a command exit status on
2, echo br> 5, echo character of the special significance of masked, so that it can appear as the character itself, the anti-oblique bars
special characters can also be masked special meaning, so that special characters lose their special meaning.
two, backslash backslash
the role of the special character of special symbolic meaning masked, it was the original character
A = 1234 echo $ A $ A appears as if we do not will be displayed as 1234 echo `display`
echo the anti-quoted string as a command to execute, we often use shell programming to the system with the results of the command assigned to a variable
A = `date`
echo $ A not shown date but the time was like a string of
file A is as follows
ABCDEFG 1234456 abcdefg B = `cat A | grep 234` # retrieve the file containing the string 234 A line
echo $ B will shown as 1234456 echo These special characters are often quoted with double quotes or single quotes will cause to these special characters, it does not have special meaning.
but there are some special characters in quotation marks, or have special meaning in double quotation marks does not work. The first four listed in this article the special characters in double quotes or special characters. It does not have special meaning for one to two single quotes with the introduction of backslash it useless.
example, we want to output as these special characters
echo the desired results, because the double quotes does not work for them, you can output these special characters in order to prototype
echo 'echo '`'
or
echoshown as in or has a special meaning, so separate out the terms, in addition to special characters if you want to output the prototype of these special characters, you can use double quotes or single quotes so that it lost a special meaning.
,;,*,?,[,] special meaning to the shell but you can use double quotation marks to enter the prototype
say is not so much we have noticed that all the special characters in single quotes loss of special meaning, if you want to output special characters prototype but remember those special characters in double quotation marks can not output the prototype, I suggest you simply use the single quotation marks. Today, the test conditions described

a statement, if conditional statement
format:
if the conditional expression
then # if the condition is true the following statement
command list
else # execute the following statements is false
command list
fi if statements can be nested
if the conditional expression 1 then if the conditional expression 2 then
command list
else if conditional expression type 3 then
command list
else
command list
fi fi else
command list
fi
you can be a multi-nested if statement must be used with a fi the end of the floor conditions that will cause a syntax error or combination of speaking in front of
Examples:
here to talk about the use of a conditional statement that tests the command test whether the conditions behind the test is true
if test- f can be changed as follows
if test-f else echo just program
. / prfile aaa
this example is to check whether your input parameter is a file if it is to print the first turn if the directory is a directory and then print the file if that is not a directory is not given prompt < br> Second, multiple condition test statement case
format:
case string in
mode) command list;;
mode) command list;;
.
esac
case of multiple conditional statement is the beginning to the end of the middle esac list of conditions can have multiple functions and the test string and the pattern did not match the inside, there's a list of commands on the implementation model which can be * denotes an arbitrary string, Finally, each mode inside the heart;; the end of double quotes, otherwise a syntax error.
following are some examples:
case $ 1 in
*. c)
cc $ 1
;;
*. txt)
lpr $ 1
;;
*)
echo
execute. / abc readme.txt file will be put through the printer
above if I will change it, you will know the results of its implementation?
case $ 1 in
*)
cc $ 1
;;
*. txt)
lpr $ 1
;;
*. c)
echo loop
one. while loop
while command format
while conditions in Table
do
command table
done
execution
shell first execution condition table, if the conditions Table a statement last exit status is zero, then the executive body of the shield ring command
table, after the implementation, then check the condition table, if the exit status of zero will continue, and so on ad infinitum until the condition table
The last statement of non-zero exit status. exit status of zero is the condition is true True.
example if the shell file reads as follows:
Sum = 0 i = 0 while true # true is the key system that really
do i = `expr $ i +1`
Sum = `expr $ Sum + $ i`
if [$ i = done echo $ i $ Sum
end of this program shows 100 5050
operation of this program is to add 1 to 100
following changes to this program and then look
Sum = 0 i = 0 while [$ i! = is the same as above, but the program should be concise
than the above cycle can be in this order until it coincided with the test conditions as the test conditions while the opposite,UGG Online Outlet, that is, when the condition is false when the body of the loop will continue statement, or exit the loop, also use the following example.
Sum = 0 i = 0 until [$ i = $ Sum + $ i `
done echo $ i $ Sum
when i is not equal to 100 cycles when the cycle when the condition is false, otherwise it exits, and the first example of this is when i is not equal to 100
when cycle, that is, the test condition is true when the loop.
two. for loop
command format:
for variable names in the list of
do
command list
done
here name list is a list of strings separated by spaces, shell in the implementation of the for loop each time followed by the name of the table
removed from a string assigned to the variable's value as a loop variable.
when the for statement in writing can also be omitted in the name list of parts, which means that the location parameter with the current time instead of the name
word list.

such as the following example in your computer there are two directories, a is aa, bb in one of these two directories in the same five files, but its
in a directory just modify one or more files, and now I forgot to change is that just a few files , then I ran strings by members of Sapporo dip tip reef ordered Ke Qu raised oval lazy Nye jealous? procedures are as follows:
for File in a1 a2 a3 a4 a5 do diff aa / $ File bb / $ File done
following re- For a list of examples with no name
for File do echo $ Filw done
save the file and execute
in a.sh in this shell in the implementation of our program is the command line as follows:
a . sh a1 a2 a3 a4 a5
execution results are as follows:
a1 a2 a3 a4 a5
we can see from this example, the command line parameters are read one by one into a
three. loop control statements
break command does not execute the body break the current cycle of the following statements from the current cycle exit.
continue the program command is ignored in the following statement through the body, from the first cycle started.
one command combinations: round brackets and braces
shell there are two ways to commands together: parentheses and curly braces. parenthesis causes the shell to create a sub-shell
to read and execute the command name enclosed. parenthesis and the right parenthesis in the command line regardless of what position, shell
that they will have a special combination of significance and only use double quotes to enclose them in reference to it in parentheses or braces
that the original meaning. For example:
echo a (b)
will get a syntax error in, in order to output a (b) only the string enclosed
echo ; (combination process is running the program, the establishment of sub-process function is very useful, because
sub-shell in the mix all the operations command in the current shell will not affect the value of each variable.
example:
child combination of command in the implementation process to change the working directory, and the new working directory command to execute a series of cases, it can not perform
return after working directory, because the child process will not affect the change in the working directory to the current working directory.
create child process will pass the current environment is also sub-shell, using export output to the current shell environment variables in each sub-shell
in equally effective.
braces can also be commands together. curly braces around the command only as a first word appears,
shell before they contain a special meaning.
difference is that with parentheses braces does not create sub-shell,UGG Online Outlet, but by the current the shell to read and execute commands enclosed
sometimes users want to use the output of a command sequence input command as another group, this time with the curly braces is the square
it.
whether it is not the curly braces with parentheses, are equal to the last exit status of commands enclosed exit status.
Second, you can perform in the current shell users to use the shell command
sure to know who is can be executed in the current shell command that can not be
executed in the current shell commands:
break case cd continue echo eval exec exit export for if read readonly return set shift test times trap umask until wait while
: {}

没有评论:

发表评论