免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: ID525
打印 上一主题 下一主题

提取文件名 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2008-07-23 12:07 |只看该作者
爱死你们了

论坛徽章:
0
12 [报告]
发表于 2008-07-23 12:35 |只看该作者
为啥没人用basename呢.

论坛徽章:
0
13 [报告]
发表于 2008-07-23 12:49 |只看该作者
能用吗???

[ 本帖最后由 ID525 于 2008-7-23 12:51 编辑 ]

论坛徽章:
0
14 [报告]
发表于 2008-07-23 13:03 |只看该作者
原帖由 bikecheng 于 2008-7-23 12:35 发表
为啥没人用basename呢.


basename怎么用?

人家是在echo中挑。。。。。

论坛徽章:
0
15 [报告]
发表于 2008-07-23 13:43 |只看该作者

回复 #9 无声无息 的帖子

和我的想法一样,呵呵

论坛徽章:
0
16 [报告]
发表于 2008-07-23 13:44 |只看该作者

回复 #6 beauty2003 的帖子

这个分隔符倒是第一次见

论坛徽章:
0
17 [报告]
发表于 2008-07-23 13:53 |只看该作者

论坛徽章:
0
18 [报告]
发表于 2008-07-23 14:01 |只看该作者
呵呵,看来会parmmeter substitution的人不是很多啊,建议好好看看

《Advanced Bash-Scripting Guide》

取前三个字符:

a="abcdefg"
echo ${a:0:3}

取后三个字符:
a="abcdefg"
echo ${a-3)}

中间三个字符:
a="abcdefg"
echo ${a:2:3}

Table B-4. Parameter Substitution and Expansion
Expression        Meaning
${var}        Value of var, same as $var
         
${var-DEFAULT}        If var not set, evaluate expression as $DEFAULT *
${varEFAULT}        If var not set or is empty, evaluate expression as $DEFAULT *
         
${var=DEFAULT}        If var not set, evaluate expression as $DEFAULT *
${var:=DEFAULT}        If var not set, evaluate expression as $DEFAULT *
         
${var+OTHER}        If var set, evaluate expression as $OTHER, otherwise as null string
${var:+OTHER}        If var set, evaluate expression as $OTHER, otherwise as null string
         
${var?ERR_MSG}        If var not set, print $ERR_MSG *
${varERR_MSG}        If var not set, print $ERR_MSG *
         
${!varprefix*}        Matches all previously declared variables beginning with varprefix
${!varprefix@}        Matches all previously declared variables beginning with varprefix

* Of course if var is set, evaluate the expression as $var.

Table B-5. String Operations
Expression        Meaning
${#string}        Length of $string
         
${string:position}        Extract substring from $string at $position
${string:position:length}        Extract $length characters substring from $string at $position
         
${string#substring}        Strip shortest match of $substring from front of $string
${string##substring}        Strip longest match of $substring from front of $string
${string%substring}        Strip shortest match of $substring from back of $string
${string%%substring}        Strip longest match of $substring from back of $string
         
${string/substring/replacement}        Replace first match of $substring with $replacement
${string//substring/replacement}        Replace all matches of $substring with $replacement
${string/#substring/replacement}        If $substring matches front end of $string, substitute $replacement for $substring
${string/%substring/replacement}        If $substring matches back end of $string, substitute $replacement for $substring
         
         
expr match "$string" '$substring'        Length of matching $substring* at beginning of $string
expr "$string" : '$substring'        Length of matching $substring* at beginning of $string
expr index "$string" $substring        Numerical position in $string of first character in $substring that matches
expr substr $string $position $length        Extract $length characters from $string starting at $position
expr match "$string" '\($substring\)'        Extract $substring* at beginning of $string
expr "$string" : '\($substring\)'        Extract $substring* at beginning of $string
expr match "$string" '.*\($substring\)'        Extract $substring* at end of $string
expr "$string" : '.*\($substring\)'        Extract $substring* at end of $string

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
19 [报告]
发表于 2008-07-23 14:03 |只看该作者

回复 #12 bikecheng 的帖子

期待你的basename版本的

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
20 [报告]
发表于 2008-07-23 14:05 |只看该作者

回复 #18 gucuiwen 的帖子

如果文件名里面的字符位数不确定怎么办?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP