percent
TLDR
Bring most recent background job to foreground
SYNOPSIS
% [jobspec_]
DESCRIPTION
% in shell context typically refers to job control, bringing background jobs to the foreground. It's shorthand for the fg command.
When a command is suspended (Ctrl+Z) or run in background (&), it gets a job number. The % notation provides quick access to these jobs.
In arithmetic contexts $(( )), % is the modulo operator, returning the remainder of integer division.
In prompt strings (PS1), % introduces escape sequences in zsh for dynamic prompt elements.
In printf/strftime, % introduces format specifiers.
EXAMPLES
sleep 100 &
# [1] 12345
# Bring to foreground
%1
# In arithmetic
remainder=$((17 % 5)) # Result: 2
# In zsh prompt (show current directory)
PS1='%~ $ '
JOB SPECIFICATIONS
% or %+ or %%
Current (most recent) job%-
Previous job%n
Job number n%string
Job whose command starts with string%?string
Job whose command contains string
CAVEATS
Job control requires an interactive shell. Not available in scripts by default.
The % interpretation is context-dependent: job control at command position, modulo in arithmetic, format specifier in strings.
Job numbers reset when the shell restarts.


