Getting ready

In earlier recipes, we introduced the use of trap to catch signals, and the use of kill to send signals to processes. These will be explained further in this recipe, but here are three new native Bash variables:

  • $$: Which returns the PID of the current script
  • $?: Which returns the PID of the last job that was sent to the background
  • $@ :Which returns the array of input variables (for example, $!, $2)
We are skirting around the ideas of jobs, tasks, background, and foreground as they will appear again in proper detail in a later administrative recipe.

Get Bash Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.