[英]change alias with directory bash
Is it possible to modify ~/.bashrc
such that when I change directory alias also changes是否可以修改
~/.bashrc
以便当我更改目录别名时也更改
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
例如,当我在目录
/home/user/Desktop
时,python3 别名是alias python3=/usr/bin/python3
当我在目录/home/user/Downloads
时,python3 别名是python3=/opt/conda/bin/python3
Make it a shell function that checks the current directory and executes the appropriate version.使其成为 shell function 检查当前目录并执行适当的版本。
python3() {
case "$PWD" in
/home/user/Desktop) /usr/bin/python3 "$@" ;;
/home/user/Downloads) /opt/conda/bin/python3 "$@" ;;
*) /some/other/python3 "$@" ;;
esac
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.