如何为grep -R编写别名? [英] How do I write an alias for grep -R?

查看:60
本文介绍了如何为grep -R编写别名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最终输入

grep -Rni pattern .

很多.如何将其设置为别名

and awful lot. How do I make this into an alias like

alias gr='grep -Rni $@ .'

运行可以提供:

$ gr pattern
grep: pattern: No such file or directory

即使别名看起来很好:

$ type gr
gr is aliased to `grep -R $@ .'

似乎$ @和.在实际执行时被交换.

It seems that the $@ and the . get swapped when it's actually executed.

推荐答案

创建一个函数而不是别名.将其保存在mylibrary.sh等文件中,每当您要使用该功能时,都将其作为源文件

make a function instead of alias. Save it in a file eg mylibrary.sh and whenever you want to use the function, source the file

例如mylibrary.sh

eg mylibrary.sh

myfunction(){
 grep -Rni ...
}

#!/bin/bash
source mylibrary.sh
myfunction 

这篇关于如何为grep -R编写别名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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