Define alias that references other aliases

前端 未结 4 1880
被撕碎了的回忆
被撕碎了的回忆 2021-02-05 17:53

I\'d need to be able to define an alias in a Debian shell that includes other aliases, for a project I\'m currently working on.

Let\'s look at a code example to make thi

相关标签:
4条回答
  • 2021-02-05 18:48

    I used this in csh and it worked for me :

    alias new_alias 'vi old_alias'

    0 讨论(0)
  • 2021-02-05 18:48

    Here is an example of alias that i'm using

    #clear
    alias cls='clear; ls'
    alias ccls='cd; cls' # used alias cls
    
    0 讨论(0)
  • 2021-02-05 18:56

    To reuse alias in another alias use:

    foobar='foo;bar'
    

    However I would suggest you to consider using shell function to get better control over this.

    0 讨论(0)
  • 2021-02-05 18:58

    Following @anubhava's sage advice:

    foo() { echo foo; }
    bar() { echo bar; }
    foobar() { echo "$(foo)$(bar)"; }
    fooandbar() { echo "$(foo)and$(bar)"; }
    

    Spaces and semicolons inside {} are required there.

    0 讨论(0)
提交回复
热议问题