I was reading a book about Linux. It states that to bring a process to foreground, use the fg
command and a percent sign (%) followed by the job number. I did some testing and found that it works as expected. But I also found that I can use a simple number as the jobspec, like fg 3
(instead of fg %3
), which can bring the third process to foreground, too. Is a simple number can be considered a valid jobspec?
Asked
Active
Viewed 82 times
0

Fajela Tajkiya
- 1,005
1 Answers
2
Bash seems to accept fg 3
etc., but I'm not sure the documentation is too explicit about that.
The description for fg
just says it takes a "jobspec", and their description says "The character ‘%’ introduces a job specification (jobspec)." and the %
seems included in all the examples.
The other shells I tried (Dash, ksh and zsh) didn't accept a plain number there, so it looks like a Bash-only thing.
Note that kill
can take a jobspec or a process ID, so both kill %3
and kill 3
are valid, they just mean different things. Which also implies that in general, a plain number can't work as a jobspec, so perhaps better to stick with %3
.

ilkkachu
- 138,973
fg 3
,fg %3
or%3
will bring job [3] back to foreground. If there is only one background job,fg
will also bring it back. Regardless of the specification, none of those versions is ambiguous. – Paul_Pedant Apr 11 '22 at 10:12