korn shell linux,korn shell点滴

$cat test.txt

ffff

oooo

$xxx=$($echo $xxx

ffff oooo

算数操作

$((arithmetic-expression))

$ echo $((3+5))

8

变量属性

typeset -attribute variable=value

或者

typeset -attribute variable

小写/大写属性-l/-u

$ typeset -l MYSYS=ASPD

$ print $MYSYS

aspd

只读属性 -r

$ typeset -r BACKUP_PATH=/backup

整数属性-i

$ typeset -i NUM=1

$ typeset -i NUM=$(who | wc -l)

$ typeset --i NUM=abc

/bin/ksh: NUM: bad number

浮点数属性-E, -F

-E 有效位数

-F 精度

$ typeset --E5 X=123.456

$ print $X

123.46

$ typeset --F5 X=123.456

$ print $X

123.45600

自动export属性-x

$ typeset --x PATH=$PATH:/lbin

多重属性

$ typeset --ix TMOUT=3000

变量扩展

${#variable}

length of variable

${variable:?-word}

value of variable if set and not null, else print word

${variable:= word}

value of variable if set and not null, else variable is set to word, then expanded

${variable:+word}

value of word if variable is set and not null, else nothing is substituted

${variable:?}

value of variable if set and not null, else print 'variable: parameter null or not set'

${variable:?word}

value of variable if set and not null, else print value of word and exit

${variable #pattern}

value of variable without the smallest beginning portion that matches pattern

${variable ##pattern}

value of variable without the largest beginning portion that matches pattern

${variable%pattern}

value of variable without the smallest ending portion that matches pattern

${variable%%pattern}

value of variable without the largest ending portion that matches pattern

${variable//pattern1/pattern2}

replace all occurrences of pattern1 with pattern2 in variable

数组

$ X=A

$ X[1]=B #X[0]仍然是A

数组赋值和声明

variable[0]=value variable[1]=value. . . variable[n]=value

set -A variable value0 value1 . . . valuen

typeset variable[0]=value variable[1]=value. . .variable[n]=value

数组变量

${array}, $array

array element zero

${array[n]}

array element n

${array[n+2]}

array element n+2

${array[$i]}

array element $i

${array[*]}, ${array[@]}

all elements of an array

${#array[*]}, ${#array[@]}

number of array elements

${#array[n]

length of array element n

${!array[*]}, ${!array[@]}

all initialized subscript values

${!array[*]:n:x}

x array elements starting withelement n

${!array[@]:n}

all array elements starting with element n

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值