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

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

    There is a way of doing it globally without adding lines to each script you execute: by using the BASH_ENV variable.

    Here is my setup for OS X 10.8.5:

    /etc/launchd.conf:

    setenv BASH_ENV /Users/DK/.env
    

    ~/.bash_profile:

    # == Bash setup for interactive shells ==    
    # === Environment for all shells ===
    . $BASH_ENV    
    # [skipped]
    

    ~/.env:

    # == Setup for all shells ==
    # This is executed for all interactive and for non-interactive shells (e.g. scripts)
    
    shopt -s expand_aliases extglob xpg_echo
    
    # [skipped] Misc. variables and PATH setup
    
    # === General aliases ===
    
    alias pause='echo "Press [Return] or [Enter] to continue..."; read' # read -p does not display prompt in Eclipse console
    
    # [skipped]
    

提交回复
热议问题