别名与在bash变量 [英] Alias with variable in bash

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

问题描述

我想创建庆典这样一个别名:

I want to create an alias in bash like this:

alias tail_ls="ls -l $1 | tail"

因此​​,如果有人类型:

Thus, if somebody types:

tail_ls /etc/ 

它只会显示最后10目录中的文件。

it will only show the last 10 files in the directory.

$ 1 似乎并没有为我工作。有什么办法,我可以介绍在bash变量。

But $1 does not seem to work for me. Is there any way I can introduce variables in bash.

推荐答案

我想创建一个函数,该函数,而不是别名,然后出口,就像这样:

I'd create a function for that, rather than alias, and then exported it, like this:

function tail_ls { ls -l "$1" | tail; }

export -f tail_ls

请注意 -f 开关置于导出:它告诉它要导出的函数。把这个在你的的.bashrc ,你是好去。

Note -f switch to export: it tells it that you are exporting a function. Put this in your .bashrc and you are good to go.

这篇关于别名与在bash变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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