Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I know that $! stores the pid of the last (background) process, but what does %1 mean? I often see it together with kill and it has the same effect as kill $!. Can someone give me a hint? (Such small terms are so hard to google :-/)

share|improve this question

migrated from stackoverflow.com Apr 26 '11 at 3:44

This question came from our site for professional and enthusiast programmers.

    
Not really... google.com/search?q=percent+1+bash (see third result) –  Hello71 Apr 28 '11 at 23:08

2 Answers 2

up vote 8 down vote accepted

The % designator refers to the jobs in the current shell's job list, and returns the PID. Try help jobs.

share|improve this answer
    
What was confusing me was that man kill gives the man page for an external kill executable which says nothing about %. But bash also has a built-in kill which as a built-in has precedence over the external kill, and help kill tells us that we can use jobspecs with the built-in kill, and that being able to use jobspecs is one of the reasons why it is a built-in. –  Ciro Santilli Oct 7 '13 at 15:56

What you want to Google is man bash

There are a number of ways to refer to a job in the shell. The charac- ter % introduces a job name. Job number n may be referred to as %n. A job may also be referred to using a prefix of the name used to start it, or using a substring that appears in its command line. For exam- ple, %ce refers to a stopped ce job. If a prefix matches more than one job, bash reports an error. Using %?ce, on the other hand, refers to any job containing the string ce in its command line. If the substring matches more than one job, bash reports an error. The symbols %% and %+ refer to the shell's notion of the current job, which is the last job stopped while it was in the foreground or started in the back- ground. The previous job may be referenced using %-. When there is the current job only, %- refers to the shell's notion of the current job. In output pertaining to jobs (e.g., the output of the jobs com- mand), the current job is always flagged with a +, and the previous job with a -. A single % (with no accompanying job specification) also refers to the current job.

Simply naming a job can be used to bring it into the foreground: %1 is a synonym for ''fg %1'', bringing job 1 from the background into the foreground. Similarly, ''%1 &'' resumes job 1 in the background, equivalent to ''bg %1''.

TL;DR: %1 is job number 1.

share|improve this answer
3  
I thought quality was job number 1... –  Ignacio Vazquez-Abrams Apr 24 '11 at 22:00
1  
@Ignacio Vazquez-Abrams: Aye, that and the demands of nature. –  Orbling Apr 24 '11 at 22:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.