How to save multiple $! into variables and use it later in bash?

前端 未结 3 1410
無奈伤痛
無奈伤痛 2021-01-27 07:02

I want to get the pids of two background processes,

sleep 20 & pid1=$\\!; sleep 10 & pid2=$\\!; echo \"pid1: $pid1, pid2: $pid2\"

and

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-27 07:47

    Your syntax kindly incorrect, try this:

    [root@XXX ~]# sleep 5 & pid1=$!; sleep 6 & pid2=$!; echo "pid1: ${pid1}, pid2: ${pid2}"
    [1] 2308
    [2] 2309
    pid1: 2308, pid2: 2309
    

提交回复
热议问题