python - 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")
以上没有给我任何错误,也没有改变目录
解决方案
您可以在.bashrc
文件中设置别名。使用or打开.bashrc
文件并附加以下内容。nano
vim
alias run_mel='cd desktop/reference/django/mel/python3 && manage.py runserver'
添加别名后保存并退出文件然后运行source .bashrc
然后,您应该能够通过仅运行从主目录启动服务器run_mel
推荐阅读
- asp.net - OnClick 事件触发但在 .aspx 中不可见
- combobox - 如何设置组合框值?
- java - 重构使用不同对象的 Java 11 中资源的尝试
- c# - 仅当另一个字段是 MVC 中验证的某个值时才使用 rang 进行验证
- java - 错误:尝试运行 java 程序时看到无法初始化主类
- php - 如何使用 spl_autoload() 包含多个文件夹和文件;
- node.js - 在 Visual Studio 代码中以调试模式通过背包运行节点 js
- ios - 将节点放置在 ARKit World 中的触摸位置
- python - 从 python 脚本执行 psql 命令
- android - 具有自定义布局的 Android 应用内更新对话框