我可以一次运行两个bash命令,仅将一个发送到后台吗? [英] Can I run two bash commands at once and send only one to the background?

查看:73
本文介绍了我可以一次运行两个bash命令,仅将一个发送到后台吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了避免出现XY问题,我试图设置一个iTerm配置文件以在按下热键时执行以下操作.

In the interest of avoiding an XY problem, I'm trying to set up an iTerm profile to do the following when I hit the hotkey.

  1. cd到〜/my/directory/
  2. 在后台启动http服务器
  3. 让我留在〜/my/directory/

到目前为止,我正在使用的命令是 cd〜/my/directory/&&python -m SimpleHTTPServer 8000&>/dev/null&

The command I'm working with so far is cd ~/my/directory/ && python -m SimpleHTTPServer 8000 &> /dev/null &

这非常适合在项目根目录下启动服务器.问题是,它开始在后台运行后,我的密码不是〜/my/directory/.我想那部分也将发送到后台.

This works great for starting the server on the project root. The problem is, after it starts running in the background, my pwd is NOT ~/my/directory/. I guess that part is sent to the background too.

是否有一种方法可以完成第3步而不必在以后再次手动cd?

Is there a way to accomplish step 3 without having to cd again manually afterward?

推荐答案

这对我有用

; 而不是&&

cd ~/my/directory/ ; python -m SimpleHTTPServer 8000 &> /dev/null &

()

cd ~/my/directory/ && (python -m SimpleHTTPServer 8000 &> /dev/null &)

这篇关于我可以一次运行两个bash命令,仅将一个发送到后台吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆