Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

A job specification (jobspec) is a specialized syntax used by the Bash shell’s job control facility to identify and reference background or suspended processes (jobs) executing within the current session. It allows developers to target specific process groups for shell built-in commands without requiring the system-level Process ID (PID). Jobspecs are resolved against the shell’s internal job table, which maps a sequential integer (the job number) to a specific process or pipeline. By convention, a jobspec is prefixed with a percent sign (%).

Syntax Variations

The Bash shell supports several jobspec formats for pattern matching and state-based referencing:
%n      # Targets the job with job number 'n' (where n is an integer).
%str    # Targets the job whose command line begins with the string 'str'.
%?str   # Targets the job whose command line contains the substring 'str'.
%%      # Targets the "current" job.
%+      # Targets the "current" job (synonymous with %%).
%       # Targets the "current" job (shorthand for %%).
%-      # Targets the "previous" job.

State Resolution

The shell maintains internal pointers to track job states, specifically defining the “current” and “previous” jobs:
  • Current Job (%+, %%, or %): The most recently suspended job. If no jobs are currently suspended, it resolves to the most recently backgrounded job.
  • Previous Job (%-): The job that held the “current” status immediately prior to the active current job.

Resolution Rules and Ambiguity

When utilizing string-based jobspecs (%str or %?str), the shell evaluates the provided string against the command lines stored in the job table.
  • Prefix Matching: %str requires the command line to start exactly with str.
  • Substring Matching: %?str requires str to exist anywhere within the command line.
  • Ambiguity Exception: If a string-based jobspec matches multiple active jobs in the job table, the shell cannot safely resolve the target. It will abort the operation and raise an ambiguous job spec error.
  • Missing Job Exception: If no jobs match the integer or string provided, the shell raises a no such job error.
Master Bash with Deep Grasping Methodology!Learn More