别名在Unix中查找目录 [英] Aliasing find directory in Unix

查看:190
本文介绍了别名在Unix中查找目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过这样的:

 别名fdi'find。 -typed -iname* \!^ *'

作为参数传递。



fdi abc 只会输出:

<$ p $ $ ./ d / abc

不是这个:

  ./ d / greabcyup 



我不只是在寻找确切的名字。它也应该显示 ./ d / greabcyup



更新:我没有

  echo $ 0 



tcsh

解决方案

这是c-shell还是tcsh?

我用 orielly lunix简而言之,!^ 是当前命令行中的第一个单词,所以我不认为这是在做什么想。
你可以用dbl从cmd-line检查这个理论,用 echo abc def!^ 。 (我没有csh方便)。

但很明显,当你创建别名时,它不会得到第一个单词(别名)或第一个单词信息范范范范辛辛亦信息的数范范信息这可能是关于csh评估的顺序。

一般来说,大多数shell(不仅仅是csh)中的别名都不能带参数。它将在最后附加任何包含在调用中的内容。所以你的别名扩展,用abc参数作为

  find。 -type d -iname abc 

结果你得到,支持。 (你可能会看到一些有用的打开csh调试,通过改变你的顶级哈希行到#!/ bin / csh -vx



这就是为什么其他shell有函数,

  function fdi(){
找 。 -typed -iname$ @
}

如果您不能使用另一个shell,因为策略,(bash,ksh,zsh都是强大的编程语言),而且你会定期使用csh,一定要找到'The Unix C shell Field Guide,Gail&保罗·安德森。一本写得特别好的书。



IHTH。


I tried something like:

alias fdi 'find . -type d -iname "*\!^*"' 

but this only looks for exact names passed as argument.

fdi abc will only output:

./d/abc

not this:

./d/greabcyup

I am not just looking for exact name. It should also show ./d/greabcyup

Update: I did

echo $0

tcsh

解决方案

Is this c-shell or tcsh?

I dbl-checked with orielly lunix in a nutshell , !^ is meant to be the first word in the current command line, so I don't think it is doing what you want. You can dbl check that theory for yourself, with echo abc def !^ from cmd-line. (I don't have a csh handy).

But it's clear that when you create the alias, it is not getting the first word (alias) OR the first word of the alias (find) embedded in the alias. It's probably about the order of evaluation for csh.

In general any alias in most shells (not just csh) can't take arguments. It will append whatever was included on the invocation at the end. So your alias expands, with the abc argument as

find . -type d -iname abc

And the results your getting, support that. (You might see something helpful by turning on the csh debugging, by changing your top hash-bang line to #!/bin/csh -vx )

This is why other shells have functions,

 function fdi() {
     find . -type d -iname "$@"
 }

If you can't use another shell because of policy, (bash,ksh,zsh are all powerful programming languages), and you're going to use csh regularly, be sure to pickup a copy of the 'The Unix C shell Field Guide, Gail & Paul Anderson. A really exceptionally well written book.

IHTH.

这篇关于别名在Unix中查找目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆