Can I run two bash commands at once and send only one to the background?

我们两清 提交于 2021-01-29 06:26:39

问题


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 to ~/my/directory/
  2. start an http server in the background
  3. let me stay in ~/my/directory/

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

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.

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


回答1:


This works for me

; instead of &&

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

or second command in ( )

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


来源:https://stackoverflow.com/questions/55521091/can-i-run-two-bash-commands-at-once-and-send-only-one-to-the-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!