将通配符传递给别名 [英] Pass wildcard to alias

查看:57
本文介绍了将通配符传递给别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用修改列表命令作为别名(在KSH中):

I use a modifies list command as alias (in KSH):

alias ltf='ls -lrt -d -1 $PWD/*'

因此,命令ltf显示如下内容:

So the command ltf displays something like this:

-rw-r--r-- 1 myuser mygroup 0 Apr 18 12:00 /usr/test.txt
-rw-r--r-- 1 myuser mygroup 0 Apr 18 12:00 /usr/test.log

现在我要使用通配符.但是使用ltf *.log无效.

Now I want to use wildcards. But using ltf *.log does not work.

实现此目标的最佳方法是什么?

What is the best way to achieve that?

更新:我想指定我的问题,因为到目前为止答案还不能解决我的问题:命令ls -lrt -d -1 $PWD/*执行带有某些选项的list命令,并且显示完整路径,这对我来说很重要.

Update: I want to specify my question because the answers does not solve my problem so far: the command ls -lrt -d -1 $PWD/* executes a list command with some options AND it displays the full path, which is an important point for me.

很遗憾,别名方法不允许使用通配符参数.我的目标是使这成为可能.也许这是将命令作为函数创建的最佳方法.答案中提到了这一点,但目前尚无法解决(请参见评论).

Unfortunately the alias approach does not allow wildcard parameters. My goal is to make this possible. Probably it is the best way to create the command as a function. This is mentioned in the answers, but it does not work yet (see comments).

有什么想法吗?

推荐答案

使用shell函数代替别名:

Use a shell function instead of an alias:

function ltf {
  if [ -z "$1" ]; then
    ls -lrtd1 ${PWD}/*
  else
    ls -lrtd1 $1
  fi
}

这篇关于将通配符传递给别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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