相关疑难解决方法(0)

命令/别名可以变量吗?

我需要不时查看日志文件的特定行:

$ head -10 log.txt|tail -1  # to view line 10 of log.txt
Run Code Online (Sandbox Code Playgroud)

然后我v在我写了一个函数,bashrc让生活更轻松:

$ v 10
Run Code Online (Sandbox Code Playgroud)

好吧,也许我这里有点分裂:我也想忽略这个空间:

$ v10
Run Code Online (Sandbox Code Playgroud)

我知道的唯一方法是定义许多别名:

alias v1='v 1'
alias v2='v 2'
alias v3='v 3'
alias v4='v 4'
...
Run Code Online (Sandbox Code Playgroud)

这有什么好办法吗?


感谢@Chirlo和@anishsane的想法.

这是我的最终版本,基于@ anishsane的一些修复:

eval "`declare -f command_not_found_handle | sed s/command_not_found_handle/command_not_found_handle_orig/`"
command_not_found_handle(){
    if expr match "$1" "v[0-9][0-9]*" >/dev/null ; then
       v ${1:1}
       return $?
    fi
    command_not_found_handle_orig "$@"
}
Run Code Online (Sandbox Code Playgroud)

bash shell alias

2
推荐指数
1
解决办法
246
查看次数

标签 统计

alias ×1

bash ×1

shell ×1