You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何用Bash脚本并行启动程序并在新终端运行Android模拟器

Fix: Launch Expo and Android Emulator in Separate Terminals

Got it, let's get this sorted out for you. The issue with your original script is that exp start runs in the foreground, blocking the rest of the commands until it exits—plus even if you background it, everything runs in the same terminal window. Here's how to launch Expo and spin up a new terminal for the emulator at the same time, tailored to different terminal apps:

For GNOME Terminal (Ubuntu, Fedora, etc.)

Update your script to this:

#!/bin/bash
# Start Expo in the current terminal (backgrounded so the next command runs immediately)
cd App && exp start &
# Launch a new GNOME Terminal and run the emulator
gnome-terminal -- bash -c "cd ~/Android/Sdk/emulator && ./emulator; exec bash"
  • The & after exp start backgrounds Expo, so the script doesn't wait for it to finish before opening the emulator terminal.
  • exec bash keeps the emulator terminal open after the emulator exits (remove this part if you want it to close automatically).

For Konsole (KDE Desktop Environments)

Use this version instead:

#!/bin/bash
cd App && exp start &
konsole -e "bash -c 'cd ~/Android/Sdk/emulator && ./emulator; exec bash'" &
  • The -e flag tells Konsole to run the specified command in the new window.

For Xterm (Lightweight Terminal)

If you use Xterm, adjust the script like so:

#!/bin/bash
cd App && exp start &
xterm -e "bash -c 'cd ~/Android/Sdk/emulator && ./emulator; exec bash'" &

For macOS Terminal.app

On macOS, we use AppleScript to trigger a new Terminal window:

#!/bin/bash
cd App && exp start &
osascript -e 'tell application "Terminal" to do script "cd ~/Android/Sdk/emulator && ./emulator"'
  • This will open a new Terminal tab/window and run the emulator command automatically.

Quick Tip

You can skip the cd command for the emulator by using the full absolute path directly:

# Example for GNOME Terminal
gnome-terminal -- bash -c "~/Android/Sdk/emulator/emulator; exec bash"

This makes the script a bit cleaner and avoids any path-related issues.

Test out the version that matches your terminal app—this should launch Expo and the emulator in separate windows at the same time.

内容的提问来源于stack exchange,提问作者mrfr

火山引擎 最新活动