在外壳脚本的后台运行cmd



如何在后台运行cmd并返回到shell脚本中的下一行test.sh ->

bash --rcfile <(echo '. ~/.bashrc; ./cloud_sql_proxy -instances=connectionstring && exit')
mysql -u root -p --host 127.0.0.1

第一个 cmd 给出的输出为

2018/01/05 01:49:28 Listening on 127.0.0.1:3306 for connectionstring
2018/01/05 01:49:28 Ready for new connections

所以 2 cmd 永远不会被执行。

基本上我想在后台运行 1 cmd,以便执行 2 cmd。

我有办法解决问题

cmd="./cloud_sql_proxy -instances=connectionstring"
echo "starting service"
$cmd </dev/null >proxy.out 2>proxy.err &
mysql -u root -p --host 127.0.0.1

将"&"附加到行尾将在后台运行它。

例如。$ ls -l &

最新更新