栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

bash-最后一个特定字符后的表达

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

bash-最后一个特定字符后的表达

它是外壳程序的几种功能之一,通常称为 外壳扩展 。这种特定的 扩展 称为 参数 扩展*。

您可以将这种特殊的Shell扩展形式视为 左截断 字符串函数。您必须使用如图所示的花括号(这不是可选的)。

如果仅使用一个

#
,则表示仅左截断随后出现的模式的 第一个 匹配项(直到结束
}
。使用两个时
##
,表示左截断 所有
连续的模式匹配。的结果
var="a/b/c"; echo ${var#*/}
b/c
echo ${var##*/}
返回
c

有一个互补的 右截断 。它使用

%
而不是
#
…(我“记住”,这是因为
#
它像bash注释一样;始终在左侧)。

*
被视为一个bash通配符扩展。

这是所有shell扩展的列表,按优先级顺序显示。

扩展顺序为:

1. brace expansion ... prefix{-,,}postfix  # prefix-postfix prefix,postfix         .. {oct,hex,dec,bin}    # oct hex dec bin          . {a..b}{1..2}         # a1 a2 b1 b2          . {1..04}   # 01 02 03 04          . {01..4}   # 01 02 03 04          . {1..9..2} # 1 3 5 7 9          . $'\x{0..7}{{0..9},{A..F}}'  # $'x00' .. $'x7F'2. tilde expansion .... ~# $HOME         ... ~axiom      # $(dirname "$HOME")/axiom... ~fred       # $(dirname "$HOME")/fred          .. ~+          # $PWD     (current working directory)          .. ~-          # $OLDPWD  (previous working directory. If OLDPWD is unset, ~- is not expanded. ie. It stays as-is,   regardless of the state of nullglob.)   # Expansion for Directories in Stack. ie.    # The list printed by 'dirs' when invoked without options . ~+N         #    Nth directory in 'dirs' list (from LHS). ~-N         #    Nth directory in 'dirs' list (from RHS)3. parameter expansion .... ${VAR/b/-dd-}    ... ${TEST_MODE:-0}   .. ${str: -3:2}  # note space after :    . ${#string}4. (processed left-to-right)      variable expansion      arithmetic expansion     command substitution▶5. word splitting          # based on $IFS (Internal Field Seperator)▷6. pathname expansion      according to options such as:         nullglob, GLOBIGNORE, ...and more# Note: ===============▶ 5. word splitting     ↰ ▷ 6. pathname expansion ↰  # =====================  ↳  are not performed on words between  [[  and  ]]


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/412640.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号