摘要:export和alias都是用来简化命令行输入的工具。export用于设置环境变量,环境变量是一些系统级别的变量,用于指定一些系统的默认值或者搜索路径等。
alias用于给较长的命令取别名,只是给命令取别名。
一、alias
alias ll="ls -l"
这样就可以使用简单的命令执行操作
二、export
环境变量配置文件.bash_profile:
# Setting PATH for Python 3.6 # The original version is saved in .bash_profile.pysave PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}" export PATH # Setting PATH for Python 3.10 # The original version is saved in .bash_profile.pysave # 冒号(:)通常表示分隔符,将前面的路径添加到PATH系统环境变量中,再调用export设置,最后保存文件别忘了source激活 PATH="/Library/Frameworks/Python.framework/Versions/3.10/bin:${PATH}" export PATH alias python3="/usr/local/bin/python3.10" alias python36="/usr/local/bin/python3.6"
注意点:
当我输入$PATH查看系统的环境变量时
-bash: /Library/Frameworks/Python.framework/Versions/3.10/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/Library/Frameworks/Python.framework/Versions/3.10/bin:/Library/Frameworks/Python.framework/Versions/3.10/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/Library/Frameworks/Python.framework/Versions/3.10/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/Library/Frameworks/Python.framework/Versions/3.10/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin: No such file or directory
所以当我没加别名alias时,输入python3加载的是python3.10版本而不是3.6版本。(linux中当我输入命令,会到系统环境变量指定的目录中查找可执行文件,没有找到则报错),这里优先找到了3.10/bin下的python3
版权声明:除特别声明外,本站所有文章皆是本站原创,转载请以超链接形式注明出处!