简体   繁体   中英

change alias with directory bash

Is it possible to modify ~/.bashrc such that when I change directory alias also changes


eg When I am in directory /home/user/Desktop python3 alias is alias python3=/usr/bin/python3 and when I am in directory /home/user/Downloads python3 alias is python3=/opt/conda/bin/python3

Make it a shell function that checks the current directory and executes the appropriate version.

python3() {
    case "$PWD" in
    /home/user/Desktop) /usr/bin/python3 "$@" ;;
    /home/user/Downloads) /opt/conda/bin/python3 "$@" ;;
    *) /some/other/python3 "$@" ;;
    esac
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM