CMD List [9]

1          Shell

1.1         variable ( $ )

System variable.

Option

Function

$abc

${abc}

abc = "blue"

echo ${abc}

$(command)

e.g. v1 = "$(hostname)", v2 = "$(pwd)"

$?

Expands to the exit status of the most recent pipeline. (last status code)

$n

$1 first argument, $2 second …

$#

Count of argument of command line

$0

Program name.

$*

Store all argument with “arg1 arg2 …”

$@

Store all argument with “arg1” “arg2” …

Note: If using in “…”, add {}, e.g. “… ${0} …”

 

User variable

e.g. name="Winter" echo $name

 

Environment variable

e.g. PATH, LOGNAME (logon user name)…

 

{}

Concatenate variable and string. E.g. SAT=Satur echo ${SAT}day

 

Unset

Clean variable. E.g. unset a

 

readonly

Content of variable can’t be changed. E.g. readonly a=2;unset a;echo “a=$a”;

 

array

e.g. name[0]=”a”;name[1]=”b”; echo ${name[$i]};

 

1.2         typeset

typeset [options] [variable[=value ...]]

 

Korn shell only. Assign a type to each variable. -option enables the type and +option disables it.

 

argument

Function

i

Integer, e.g. typeset -i n1 n2 n3

(nil)

Character, e.g. typeset sh_name

e.g.

typeset +r PWD End read-only status of PWD.

 

1.3         let

let expressions

     or

((expressions))

 

Korn shell only. Specified by one or more integer expressions which consist of numbers, operators, shell variables. Expressions must be quoted if they contain spaces.

e.g.

i=`expr $i + 1`

let i=i+1

let "i = i + 1"

(( i = i + 1 ))

let $a + $b

 

1.4         Control Statement

while [condition]  (or [[ … ]])

do

    …

done (or done < InputFile)

 

for string in list

do

    …

done

 

if / elif [condition] (or [[ … ]])

then

    …

(else)

    …

fi

 

 

Operation in control statement

Operator

[[ ]]

 

-a file

-d file

-e file

-f file

-r file

-s file

-w file

-x file

 

-O file

-G file

1 -nt 2

1 -ot 2

 

-lt

 

!=, >, <

-n str

-z str

 

&&,||,-a,-o

True if...

It is better integrated into the Korn shell, it provides many options to check different attributes of a file, returns an exit status.

True if the file exists.

file is a directory

True if the file exists.

file is a regular file (i.e., not a directory or other special type of file)

You have read permission on file

file exists and is not empty

You have write permission on file

You have execute permission on file, or directory search permission if it is a directory

You own file

Your group ID is the same as that of file

file1 is newer than file2

file1 is older than file2

 

Less than (other like -le, -eq, -ge, -gt, -ne)

 

Normal compare.

Str is not null (length greater than 0).

Str is null (length is 0).

 

Seems same as and (&&) or (||).

 

Other

break

Exit from a while or for loop.

continue

Begin next iteration of while or for loop without reaching the bottom.

exit

Do not execute remaining instruction and read no new input. END procedures will be executed.

return [expr]

For nawk. Used at end of user-defined functions to exit function, returning value of expression.

 

e.g.

if [[ -f "$ldcmd" ]]

then

       while read LINE

       do

              …

       Done < ${ldcmd}

fi

rc=$?

return ${rc}

 

if command && [[ condition_1 || condition_2 ]]; then …

while [ $hour -le 0030 -o $hour -ge 2200 ]

 

1.5         Function

function  function_name () {commands; commands; }

unset -f function_name

 

1.6         Concatenate

Ø      Break line: ( backslash \ )

Ø      Concatenate string: ( blank )

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值