JobIDExpand expands %n job id values in args with the full PID returns number of PIDs expanded
(args []string)
| 441 | // JobIDExpand expands %n job id values in args with the full PID |
| 442 | // returns number of PIDs expanded |
| 443 | func (sh *Shell) JobIDExpand(args []string) int { |
| 444 | exp := 0 |
| 445 | for i, id := range args { |
| 446 | if id[0] == '%' { |
| 447 | idx, err := strconv.Atoi(id[1:]) |
| 448 | if err == nil { |
| 449 | if idx > 0 && idx <= len(sh.Jobs) { |
| 450 | jb := sh.Jobs[idx-1] |
| 451 | if jb.Cmd != nil && jb.Cmd.Process != nil { |
| 452 | args[i] = fmt.Sprintf("%d", jb.Cmd.Process.Pid) |
| 453 | exp++ |
| 454 | } |
| 455 | } else { |
| 456 | sh.AddError(fmt.Errorf("cosh: job number out of range: %d", idx)) |
| 457 | } |
| 458 | } |
| 459 | } |
| 460 | } |
| 461 | return exp |
| 462 | } |