代码之家  ›  专栏  ›  技术社区  ›  showkey

如何在alias中设置函数参数?

  •  0
  • showkey  · 技术社区  · 8 年前

    这里是我的函数git推送wordpress目录。

    pushwp(){
    cd /var/www/html/wp
    git init
    git add *
    git commit -am  "$1"
    git push -f origin master
    }
    

    pushwp功能处于良好状态。

    pushwp  "it is a test"
    Reinitialized existing Git repository in /var/www/html/wp/.git/
    On branch master
    nothing to commit, working directory clean
    Everything up-to-date
    

    现在为函数分配别名。

    alias pushme='pushwp(){
    cd /var/www/html/wp
    git init
    git add *
    git commit -am  "$1"
    git push -f origin master
    }'
    

    让我们试试看。

    pushme  "it is a test"
    bash: syntax error near unexpected token `"it is a test"'
    

    如何修复别名?

    1 回复  |  直到 8 年前
        1
  •  0
  •   VonC    8 年前

    如前所述,您需要定义并调用别名。但你不需要在这里。

    确保不要每次推送时都初始化repo:git init应该只执行一次,而不是该别名的一部分。

    你可以使用 git add . 而不是 git add * (依赖于bash扩展)