首页 > 解决方案 > python更改bash目录mac

问题描述

每天当我打开我的mac。

我打开 bash 并执行以下命令:

cd desktop 
cd reference
cd django
cd mel
cd python3 manage.py runseerver

我想让上述过程自动化,如果我运行一个 python 脚本,以上所有内容都应该在 shell 中执行。

到目前为止,当我尝试过时:

import os
wd = os.getcwd()
os.chdir("desktop") 

以上没有给我任何错误,也没有改变目录

标签: pythondjangopython-3.xpython-2.7python-3.6

解决方案


您可以在.bashrc文件中设置别名。使用or打开.bashrc文件并附加以下内容。nanovim

alias run_mel='cd desktop/reference/django/mel/python3 && manage.py runserver'

添加别名后保存并退出文件然后运行source .bashrc

然后,您应该能够通过仅运行从主目录启动服务器run_mel


推荐阅读