运行 一条命令,无需等待

Run a command without making me wait

我是 Shell 脚本的新手 Linux。
我正在使用 Android 进行自动化测试,所以我想 运行 一些 shell 脚本如下:

  1. 开始通过 adb 录制屏幕 (cmd1.sh)
  2. 进行场景测试然后 Stop/Save 记录文件 (cmd2.sh)

不幸的是,当我 运行 cmd1.sh 我必须等待 3 分钟才能 cmd2.sh 是 运行。
这意味着我无法录制视频:sad:
这是我的 运行 命令内容:

run.sh文件内容:

./cmd1.sh $
./cmd2.sh

cmd1.sh文件内容:

adb shell screenrecord /sdcard/file.mp4

cmd2.sh文件内容:

calabash-android run app.apk

最后,我打开终端然后 运行 命令:

./run.sh

当然,视频不能保存,因为cmd1.sh完成后,cmd2.sh是运行!!!
在这一点上有人可以帮助我吗?
太感谢了 !

@Jrican 已更新
这是我可以播放录像的手动步骤。
1. 打开终端 A
2. 运行命令1(开始录屏脚本)
3.打开其他终端B然后运行一个命令2
4. 命令 2 完成后,返回终端 A 然后 Ctrl C 。
5.确认/sdcard/file.mp4中的视频可以正常播放

我正在研究 MAC OSX Yosemite 10.10.5

同时运行两个命令,然后在第二个命令完成后杀死第一个命令的PID:

#!/bin/sh

# Run first command in background:
./cmd1.sh & PID="$!"

# Run second command:
./cmd2.sh

# Kill the first command:
kill "$PID"

简单的解决方案: run.sh 文件内容:

./cmd1.sh &          # run this command in the background
./cmd2.sh            # run this command to completion 
kill -SIGINT %1      # send the interrupt signal to the first command (ctrl+c)

稍微更正确的解决方案: run.sh 文件内容:

./cmd1.sh &            # run this command in the background
recPID=$!              # save the PID for this process for later
./cmd2.sh              # run this command to completion 
kill -SIGINT $recPID   # send the interrupt signal to the first command (ctrl+c)