在 find -exec 中使用别名 [英] Using an alias in find -exec

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

问题描述

我在 bash 中有一个很长的命令,我不想一直输入,所以我在我的 .profile 中放了一个别名

I have a very long command in bash, which I do not want to type all the time, so I put an alias in my .profile

alias foo='...'

现在我想使用 find -exec 来执行这个别名

Now I want to execute this alias using find -exec

find . -exec foo '{}' ;

但是 find 找不到 foo:

but find cannot find foo:

find: foo: 没有这样的文件或目录

find: foo: No such file or directory

是否可以在 find 中使用别名?

Is it possible to use an alias in find?

推荐答案

不,find 对您的别名一无所知.别名与环境变量不同,它们不会被子进程继承".

Nope, find doesn't know anything about your aliases. Aliases are not like environment variables in that they aren't "inherited" by child processes.

您可以使用相同的命令创建一个 shell 脚本,设置 +x 权限并将其放在您的路径中.这将与 find 一起使用.

You can create a shell script with the same commands, set +x permissions and have it in your path. This will work with find.

这篇关于在 find -exec 中使用别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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