How to use aliases defined in .bashrc in other scripts?

后端 未结 6 1045
情话喂你
情话喂你 2020-11-27 06:36

In ~/.bashrc, I defined some aliases. But I cannot use them in other shell scripts, where I can only use aliases defined right there. Even though I sourced bashrc, it still

6条回答
  •  离开以前
    2020-11-27 07:24

    The simplest answer is to do the 2 important things or it wont' work.

    #!/bin/bash -i
    
    # Expand aliases defined in the shell ~/.bashrc
    shopt -s expand_aliases
    

    After this, your aliases that you have defined in ~/.bashrc they will be available in your shell script (giga.sh or any.sh) and to any function or child shell within such script.

    If you don't do that, you'll get an error:

    your_cool_alias: command not found
    

提交回复
热议问题