linux shell脚本$ 什么意思,在Linux shell脚本中,'x = $ {1:3:1}'是什么意思?

这是一个参数扩展,许多与${开始的一部分。

Like $ {parameter:-word},$ {parameter:= word},$ {parameter:?word},$ {parameter:+ word}等等。

这一个(专用于ksh,bash和zsh):${parameter:offset:length}从偏移处开始提取长度字符(可选,如果缺失,参数中字符串的其余部分)。随着bash手册中描述的几个细节。

${name:offset:length}

Substring Expansion. Expands to up to length characters of the value

of parameter starting at the character specified by offset. If parameter

is @, an indexed array subscripted by @ or *, or an associative

array name, the results differ as described below. If length is omitted,

expands to the substring of the value of parameter starting at the character

specified by offset and extending to the end of the value. length and

offset are arithmetic expressions (see ARITHMETIC EVALUATION below).

If offset evaluates to a number less than zero, the value is used as an

offset in characters from the end of the value of parameter. If length

evaluates to a number less than zero, it is interpreted as an offset in

characters from the end of the value of parameter rather than a number

of characters, and the expansion is the characters between offset and

that result. Note that a negative offset must be separated from the

colon by at least one space to avoid being confused with the :- expansion.

If parameter is @, the result is length positional parameters

beginning at offset. A negative offset is taken relative to one greater

than the greatest positional parameter, so an offset of -1 evaluates

to the last positional parameter. It is an expansion error if length

evaluates to a number less than zero.

If parameter is an indexed array name subscripted by @ or *, the result

is the length members of the array beginning with ${parameter[offset]}.

A negative offset is taken relative to one greater than the maximum

index of the specified array. It is an expansion error if length evaluates

to a number less than zero.

Substring expansion applied to an associative array produces undefined

results.

Substring indexing is zero-based unless the positional parameters

are used, in which case the indexing starts at 1 by default. If

offset is 0, and the positional parameters are used, $0 is prefixed

to the list.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值