LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1181|回复: 8

变量后面加:t是什么意思?

[复制链接]
发表于 2006-8-11 15:19:01 | 显示全部楼层 |阅读模式
比如有个变量$test
$test:t
是什么意思??
发表于 2006-8-16 00:31:04 | 显示全部楼层
never seen that notation before. Are you talking about bash shell?
回复 支持 反对

使用道具 举报

发表于 2006-8-19 15:11:39 | 显示全部楼层
在zsh中,:t相当于basename

a=/boot/vmlinuz-2.6.17-1-686
echo $a:t
vmlinuz-2.6.17-1-686

确切地说是叫Modifier

类似还有

a=/boot/vmlinuz-2.6.17-1-686
echo $a:h
boot

echo $a:r
/boot/vmlinuz-2.6

echo $a:e
17-1-686

echo $a:u
/BOOT/VMLINUZ-2.6.17-1-686
回复 支持 反对

使用道具 举报

发表于 2006-8-20 10:49:25 | 显示全部楼层
good to know! Thanks!
回复 支持 反对

使用道具 举报

发表于 2006-8-20 13:59:20 | 显示全部楼层
man bash 里边的 Modifiers 栏目,都写出来了。可以看看。:)。
回复 支持 反对

使用道具 举报

发表于 2006-8-20 14:07:29 | 显示全部楼层
对,bash也一样,zsh多了几个,如l,u,Q等
回复 支持 反对

使用道具 举报

发表于 2006-8-21 12:11:17 | 显示全部楼层
true but notation like $a:t does not actually work well under bash.. any options need to be turned on?
回复 支持 反对

使用道具 举报

发表于 2006-8-22 11:01:11 | 显示全部楼层
只能用在历史编辑中

  1. $ /sbin/ifconfig
  2. eth0 ...
  3. ...
  4. $ !!:t
  5. ifconfig
  6. bash: ifconfig: command not found
复制代码



以下来自Bash FAQ 3.3

D3) Why doesn't bash have csh variable modifiers?

Posix has specified a more powerful, albeit somewhat more cryptic,
mechanism cribbed from ksh, and bash implements it.

${parameter%word}
         Remove smallest suffix pattern.  The WORD is expanded to produce
         a pattern.  It then expands to the value of PARAMETER, with the
         smallest portion of the suffix matched by the pattern deleted.

        x=file.c
         echo ${x%.c}.o
         -->file.o

${parameter%%word}

        Remove largest suffix pattern.  The WORD is expanded to produce
         a pattern.  It then expands to the value of PARAMETER, with the
         largest portion of the suffix matched by the pattern deleted.

        x=posix/src/std
         echo ${x%%/*}
         -->posix

${parameter#word}
         Remove smallest prefix pattern.  The WORD is expanded to produce
         a pattern.  It then expands to the value of PARAMETER, with the
         smallest portion of the prefix matched by the pattern deleted.

        x=$HOME/src/cmd
         echo ${x#$HOME}
         -->/src/cmd

${parameter##word}
         Remove largest prefix pattern.  The WORD is expanded to produce
         a pattern.  It then expands to the value of PARAMETER, with the
         largest portion of the prefix matched by the pattern deleted.

        x=/one/two/three
         echo ${x##*/}
         -->three

Given
         a=/a/b/c/d
         b=b.xxx

        csh                     bash            result
         ---                     ----            ------
         $a:h                    ${a%/*}            /a/b/c
         $a:t                    ${a##*/}           d
         $b:r                    ${b%.*}            b
         $b:e                    ${b##*.}           xxx
回复 支持 反对

使用道具 举报

发表于 2006-8-22 22:54:50 | 显示全部楼层
that makes sense now.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表