fwe*_*igl 7 command-line bash alias
我想为 grep 创建一个别名,如下所示:
grep argX ~/myfile
Run Code Online (Sandbox Code Playgroud)
其中 argX 是参数,而 myfile 始终相同。我怎样才能做到这一点?
Rin*_*ind 13
别名不支持位置参数,因此您需要创建一个函数(您可以将其放入~/.bashrc
)。如果你真的想要别名,你可以给那个函数起别名。
function grepMe(){
grep "$1" ~/myfile
}
Run Code Online (Sandbox Code Playgroud)
然后,如果出于某种原因您希望有一个别名,您可以为该函数创建一个别名:
alias grepAlias="grepMe"
Run Code Online (Sandbox Code Playgroud)
别名不支持参数,但您可以编写一个小脚本并将其命名为“filegrep”
#!/bin/bash
grep "$1" /home/youruser/myfile
Run Code Online (Sandbox Code Playgroud)
将脚本复制到/usr/bin
,您可以filegrep argX
在控制台中运行它。
归档时间: |
|
查看次数: |
1376 次 |
最近记录: |