sort的选项:
-u 如果有重复record则只显示一次。
ls的选项
-d 显示指定文件夹的信息,而不是文件所包含的内容。如果不指定文件夹,则显示当前文件夹得信息。
1. unix shell 加载配置文件的顺序:
/etc/profile
~/.bash_profile ~/.bash_login ~/.profile
~/.bashrc
2. PS1='`PWD`>:' 此命令为设置第一提示符为当前路径。
3. umask 002 被创建的文件夹的权限是775, 文件的权限是664
umask 022 被创建的文件夹的权限是755, 文件的权限是644
1.
在shell中EDITOR这个变量定义的是编辑命令行时所使用的编辑器。
需在.profile 中设置 EDITOR=vi , 但是仅仅是这样还不够,还不许
使用export语句导出变量:export EDITOR
2.
for i in $(ls);do
statements
done
等价于
for i in `ls`;do
statements
done
3.
假如一个命令行用[/]结尾,那么意味着,这个命令会持续到下一行
eg:
$ echo a b /
> c d /
> lizm
$ a b c d lizm
4. conditional execution
条件执行
下面是一个有用的组合
command1 && command2 || command3
command1成功了则执行command2,command1如果失败则执行comamnd3。
5.
可以使用 > 命令创建一个空文件
$ > data01
会创建文件data01,如果文件已存在则清空
6.
set -o noclobber
执行上述命令后,将不能覆盖已存在的文件。
相反的操作是
set +o noclobber
7.
文件描述符:
0 标准输入
1 标准输出
2 标准错误输入输出
3-9 其他
8.
2>operator
eg:2>out.file
通过上述命令,可以重定向标准错误输出
2和>之间不能有空格,否则2将被当做是命令参数
9.
Here documents
command <<word
or
command <<?/span>word
eg1:
$cat >> .profile <<EOF
>export TREM=sum-cmd
>export ORACLE_HOME=/apps/oracle
>EOF
eg2:
$ftp <<- END
open aspsun
user anonymous
cd /usr/pub
binary
get ksh.tar.Z
quit
END
10.
Redirect Operators and File Descriptors
<&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>|file
redirect file descriptor n to file. Create file even if noclobber is enabled.
n<&m
redirect file descriptor n input from file descriptor m.
n>&m
redirect file descriptor n output to file descriptor m.
n<>file
open file for reading and writing as file descriptor n.
n<<word
redirect to file descriptor n until word is read.
n<<?/span>word
redirect to file descriptor n until word is read; ignore leading tabs.
n<&?/span>
close file descriptor n for standard input.
n>&?/span>
close file descriptor n for standard output.
print –un args
redirect arguments to file descriptor n. If n is greater than 2, it must first be opened with exec. If n is not specified, the default file descriptor argument is 1 (standard output).
read –un args
read input line from file descriptor n. If n is greater than 2, it must first be opened with exec. If n is not specified, the default file descriptor argument is 0 (standard input).
11.
[?]符号,代表任意一个字符。
[!]符号,反转匹配 eg:[!b]除了b什么都匹配
12.
Command Substitution 命令替换
$(command)
or
`command`
第二种方式是bshl中的格式,在ksh中兼容
13.
数学运算
$((expression))
14.
tilde 波浪线
~
replaced with $HOME
~user
replaced with the home directory of user
~-
replaced with $OLDPWD (previous directory)
~+
replaced with $PWD (current directory)
15.
ksh和bsh,csh以及其他脚本的区别是,ksh有数据类型和数组,而其他
的都没有。
ksh支持四种数据类型:string,integer,float,array
※默认情况下是string类型,而且默认情况下所有的变量都是全局变量
但是也能够在函数内部生命局部变量。
16.
typeset命令也能够用于变量赋值,但是如果不是设定属性,也没什么不同
假如等号后面没有值那么,变量将被设为null:
$ X=
上面的命令后X的值是null,注意:null和undefine是不同的
typeset命令可以定义指定类型的变量
typeset -attribute variable=value
or
typeset -attribute variable
17.
declare [-afFirtx] [-p] [name[=value] ...]
typeset [-afFirtx] [-p] [name[=value] ...]
Declare variables and/or give them attributes. If no names are
given then display the values of variables. The -p option will
display the attributes and values of each name. When -p is used,
additional options are ignored. The -F option inhibits the display
of function definitions; only the function name and attributes are
printed. If the extdebug shell option is enabled using shopt, the
source file name and line number where the function is defined are
displayed as well. The -F option implies -f. The following
options can be used to restrict output to variables with the speci-
fied attribute or to give variables attributes:
-a Each name is an array variable (see Arrays above).
-f Use function names only.
-i The variable is treated as an integer; arithmetic evaluation
(see ARITHMETIC EVALUATION ) is performed when the variable
is assigned a value.
-r Make names readonly. These names cannot then be assigned
values by subsequent assignment statements or unset.
-t Give each name the trace attribute. Traced functions
inherit the DEBUG and RETURN traps from the calling shell.
The trace attribute has no special meaning for variables.
-x Mark names for export to subsequent commands via the envi-
ronment.
Using `+' instead of `-' turns off the attribute instead, with the
exception that +a may not be used to destroy an array variable.
When used in a function, makes each name local, as with the local
command. If a variable name is followed by =value, the value of
the variable is set to value. The return value is 0 unless an
invalid option is encountered, an attempt is made to define a func-
tion using ``-f foo=bar'', an attempt is made to assign a value to
a readonly variable, an attempt is made to assign a value to an
array variable without using the compound assignment syntax (see
Arrays above), one of the names is not a valid shell variable name,
an attempt is made to turn off readonly status for a readonly vari-
able, an attempt is made to turn off array status for an array
variable, or an attempt is made to display a non-existent function
with -f.
18.
Some Variable Attributes
typeset –i var
Set the type of var to be integer
typeset –l var
Set var to lower case
typeset –L var
Left justify var; the field width is specified by the first assignment
typeset –Ln var
Left justify var; set field width to n
typeset –LZn var
Left justify var; set field width to n and strip leading zeros
typeset –r var
Set var to be readonly (same as the readonly command)
typeset –R var
Right justify var; the field width is specified by the first assignment
typeset –Rn var
Right justify var; set field width to n
typeset –RZn var
Right justify var; set field width to n and fill with leading zeros
typeset –t var
Set the user-defined attribute for var. This has no meaning to the Korn shell.
typeset –u var
Set var to upper case
typeset –x var
Automatically export var to the environment (same as the export command)
typeset –Z var
Same as typeset –RZ
19.
typeset -attributes 列出所有用该属性定义的变量及值
typeset +attributes 列出所有用该属性定义的变量
20.
特殊变量
?
exit status of the last command
$
process id of the current Korn shell
-
current options in effect
!
process id of the last background command or co-process
ERRNO
error number returned by most recently failed system call (system dependent)
PPID
process id of the parent shell
21.
variable expansion