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

后端 未结 6 1049
情话喂你
情话喂你 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:34

    Stolen from enzotib on ask ubuntu: Alias are deprecated in favor of shell functions. From bash manual page:

    For almost every purpose, aliases are superseded by shell functions.

    To create a function, and export it to subshells, put the following in your ~/.bashrc:

    petsc() {
        ~/petsc-3.2-p6/petsc-arch/bin/mpiexec "$@"
    }
    export -f petsc
    

    Then you can freely call your command from your scripts.

提交回复
热议问题