shell Common Statement 2

A, shell variables $(CURDIR),$0,$1,$2,$#to explain the meaning

$(CURDIR):   CURDIR是make的内嵌变量, 为当前目录
$0:Shell本身的文件名 
$1:添加到Shell的第一个参数
$2:添加到Shell的第二个参数
$#:添加到Shell的总参数个数

Example:

SRCTREE        := $(CURDIR)    *$(CURDIR)为当前目录,相当于SRCTREE=./ 
MKCONFIG   := $(SRCTREE)/mkconfig  *相当于MKCONFIG=./mkconfig

100ask24x0_config  :   unconfig
@$(MKCONFIG) $(@:_config=) arm arm920t 100ask24x0 NULL s3c24x0
  *实际运行mkconfig 100ask24x0 arm arm920t 100ask24x0 NULL  s3c24x0
  *mkconfig:表示Shell文件名($0)
  *100ask24x0:第一个参数($1)
  *... ... $#:共6个参数,所以$#等于6

Two, ln command Detailed

ln order (full name: Link)
  ln command to create a connection, similar to Windows shortcuts, connection types are divided into hard and soft connection connection (symbolic links), with the default connection type is hard-wired for the file. If you want to create a symbolic link you must use the "-s" option.
  Hard-wired: the advantage of the link between the original file and the file is independent of the content if you delete or rename the old file, then this operation will not affect the hard-linked files, hard linked files or the original document speak.
  soft connection (symbolic links): when you delete or rename the old file, soft links to the file is no longer there and the advantages of soft link is that it can cross file system (because it is nothing but file a reference name, but not the actual data).
command parameters

-b或--backup:删除,覆盖目标文件之前的备份;
-d或-F或——directory:建立目录的硬连接;
-f或——force:强行建立文件或目录的连接,不论文件或目录是否存在;
-i或——interactive:覆盖既有文件之前先询问用户;
-n或--no-dereference:把符号连接的目的目录视为一般文件;
-s或——symbolic:对源文件建立符号连接,而非硬连接;

Example:

cd ./include           *打开子目录include/            
rm -f asm              *删除之前连接名为asm的文件
ln  -s  asm-arm asm    *重新建立一个asm连接文件,指向asm-arm文件(表示选择使用arm架构文件)
//ls -l时可以看到asm -> asm-arm

The use of three, if the comparison operator determines gt, lt, eq etc.

PS: When determining if used, needs to fill in the "fi" at the end of the determination, if block represents the end of
an example:

if [ $ACTION = "add"]
then
        ... ...;
else
     ... ...;
fi

Comparative integer used as follows:

//-eq 等于(equal)
if [ "$a" -eq "$b" ]
//-ne不等于(no equal)
if [ "$a" -ne "$b" ]
//-gt大于(greater than)
if [ "$a" -gt "$b" ]
//-ge大于等于
if [ "$a" -ge "$b" ]
//-lt小于(less than)
if [ "$a" -lt "$b" ]
//-le小于等于
if [ "$a" -le "$b" ]
//<小于(在双括号中使用)
(("$a" < "$b"))
//<=小于等于(在双括号中使用)
(("$a" <= "$b"))
//>大于(在双括号中使用)
(("$a" > "$b"))
//>=大于等于(在双括号中使用)
(("$a" >= "$b"))

In comparison string using the following:

if [ "$a" = "$b" ]          *判断=
if [ "$a" != "$b" ]         *判断!=
  
if [[ "$a" < "$b" ]]        *判断<
if [ "$a" \< "$b" ]         *判断<   注意"<"使用在[ ]结构中的时候需要被转义.
 
if [[ "$a" > "$b" ]]       *判断>
if ["$a" \> "$b" ]          *判断>   注意">"使用在[ ]结构中的时候需要被转义.

[] Parameters are the following:

-z: 判断字符串长度为0则为真
-n:判断字符串长度非0则为真
-o:或
-a:与<br>-x:可执行<br>-r:可读<br>-w:可写

Examples of parameters

*$0~$6分别指向:
* mkconfig 100ask24x0 arm arm920t 100ask24x0 NULL s3c24x0
* $0 $1 $2 $3 $4 $5 $6
*
 
53 if [ -z "$6" -o "$6" = "NULL" ] ; then               *判断$6长度若为0或等于NULL为真
54 ln -s ${LNPREFIX}arch-$3 asm-$2/arch
55 else
56 ln -s ${LNPREFIX}arch-$6 asm-$2/arch         *$6!=0,所以执行else语句, ln -s arch-s3c24x0 asm-arm/arch
                                                                               * ${LNPREFIX}未定义为空,使用软连接使asm-arm/arch指向arch-s3c24x0
                                                                               * arch:architecture,CPU架构,作用是设置CPU架构为arch-s3c24x0 架构
57 fi

Guess you like

Origin www.cnblogs.com/princepeng/p/11578994.html