【讨论】tr [A-Z] [a-z] 不 work (都是 wildcard 惹的祸)

亮兄看帖不专心:)
是不是有MM在边上啊

已经解释说了是‘用于判断是否有符合一定模式的文件存在’
dearvoid还专门改了下标题
‘都是 wildcard 惹的祸’

这么示例一下好让更多人理解
请结合9楼的代码看

[php]
prayaya@Prayaya:~/test$ rm * -rf
prayaya@Prayaya:~/test$ echo *
*
prayaya@Prayaya:~/test$ touch abc
prayaya@Prayaya:~/test$ echo *
abc
prayaya@Prayaya:~/test$ echo ab*
abc
prayaya@Prayaya:~/test$

[/php]      
[QUOTE=li-jiahuan]看到老大改标题了
想起一个很常用的应用
用于判断是否有符合一定模式的文件存在
[php]
prayaya@Prayaya:~/test$ rm * -rf
prayaya@Prayaya:~/test$ [ abc = ab* ] && echo Yes || echo No
No
prayaya@Prayaya:~/test$ touch abc
prayaya@Prayaya:~/test$ [ abc = ab* ] && echo Yes || echo No
Yes
[/php]
[/QUOTE]
不是很明白这个用法, 如果还有一个文件叫 abcd 该怎么办呢?
引用:
-(dearvoid@LinuxEden:tty3)-(~/tmp/foo)-
[18357 0] ; rm -rf *
-(dearvoid@LinuxEden:tty3)-(~/tmp/foo)-
[18357 0] ; [ abc = ab* ] && echo yes
-(dearvoid@LinuxEden:tty3)-(~/tmp/foo)-
[18357 1] ; touch abc
-(dearvoid@LinuxEden:tty3)-(~/tmp/foo)-
[18357 0] ; [ abc = ab* ] && echo yes
yes
-(dearvoid@LinuxEden:tty3)-(~/tmp/foo)-
[18357 0] ; touch abcd
-(dearvoid@LinuxEden:tty3)-(~/tmp/foo)-
[18357 0] ; [ abc = ab* ] && echo yes
bash: [: too many arguments
-(dearvoid@LinuxEden:tty3)-(~/tmp/foo)-
[18357 2] ; o


      
证明了我说的是实话
我不常用这方法所以也就记不住。。。

完整的代码应该是这样的吧
[php]
prayaya@Prayaya:~/kk$ [ "$(echo ab*)" != "ab*" ] && echo Yes || echo No
No
prayaya@Prayaya:~/kk$ touch abc
prayaya@Prayaya:~/kk$ [ "$(echo ab*)" != "ab*" ] && echo Yes || echo No
Yes
prayaya@Prayaya:~/kk$ touch abcd
prayaya@Prayaya:~/kk$ [ "$(echo ab*)" != "ab*" ] && echo Yes || echo No
Yes
prayaya@Prayaya:~/kk$
[/php]
希望不会再错了。。。      
不好用 forget it      
[QUOTE]
[14859 0] ; touch a
-(dearvoid@LinuxEden:tty3)-(~/tmp/foo)-
[14859 0] ; echo Hello World | tr [A-Z] [a-z]
aello aorld
[/QUOTE] 脑子短路了,没有理解是怎么传递的      
引用:
-(dearvoid@LinuxEden:tty3)-(~/tmp)-
[24898 0] ; mkdir foo
-(dearvoid@LinuxEden:tty3)-(~/tmp)-
[24898 0] ; cd ./foo
-(dearvoid@LinuxEden:tty3)-(~/tmp/foo)-
[24898 0] ; echo [a-z]
[a-z]
-(dearvoid@LinuxEden:tty3)-(~/tmp/foo)-
[24898 0] ; touch a
-(dearvoid@LinuxEden:tty3)-(~/tmp/foo)-
[24898 0] ; echo [a-z]
a
-(dearvoid@LinuxEden:tty3)-(~/tmp/foo)-
[24898 0] ; touch k
-(dearvoid@LinuxEden:tty3)-(~/tmp/foo)-
[24898 0] ; echo [a-z]
a k
-(dearvoid@LinuxEden:tty3)-(~/tmp/foo)-
[24898 0] ; o


      
忘记回帖了,半夜脑袋果然清晰,昨天睡觉的时候想通了。:w