无法在bash脚本中调用别名

时间:2016-10-14 19:59:34

标签: bash macos

我有一个名为~/.gotorc的文件,其中包含

alias goto_usr="cd /usr"
alias goto_bin="cd /user/local/bin"

然后在.zshrc我有

source ~/.gotorc
goto() {
    `goto_$1`
}

但是当我运行goto bin时,它会显示goto:bin: command not found: goto_bin。但是,如果我运行goto_bin,那么它可以工作,我会转到预期的文件夹。

怎么回事?

1 个答案:

答案 0 :(得分:2)

您可以像这样定义单个函数<html> <head> <body class="night "> <script type="text/javascript" src="http://static.criteo.net/js/px.js?ch=1"> <script type="text/javascript" src="http://static.criteo.net/js/px.js?ch=2"> <div id="nav" class="clearfix m-reset-position"> <div id="site" class="m-reset-padding m-reset-margin"> <div class="wrapper clearfix m-reset-padding"> <div class="grid-full"> </div> <div class="grid m-reset-float"> <div class="grid-main grid-main m-reset-margin"> <div class="nav bspace rbl-block"> <div id="commentFormContainer" class="rbl-block wblock mark-bg dC"> <ul id="itemsStream" class="comments-stream"> <li class="entry iC "> <div class="wblock lcontrast dC " data-id="20085297" data-type="entry"> <ul class="sub"> </li> 而不是别名:

goto

然后将其用作:

goto() {
    case "$1" in
       usr)
       cd /usr;;
       bin)
       cd /usr/local/bin;;
    esac
}