On Fri, 2006-02-03 at 15:15 -0500, Kanwar Ranbir Sandhu wrote: > Hi Everyone, > > I'm writing a little bash script that's going to be integrated into > another application. The script itself checks if the user has any print > jobs, and if so, lists them. The user then has the opportunity to > cancel a print job. Simple enough. > > I want to check that the job ID being entered actually exists. If it > doesn't, the script should let the user know. > > My problem is that I don't know how to compare the ID entered against > the list of the user's current print job IDs. It looks to me like awk > is the way to go, but I'm not sure how to do it. I've tried a few > different awk statements, but none have worked. > > Here's the script in its current form: > > #!/bin/bash > > until [ "$answer" = 0 ]; do > JOBS=$(lpq -a | grep `id -un`) > JOB_IDS=$(lpq -a | grep `id -un` | tr -s " " | cut -d " " -f 3) > if [ -z "$JOBS" ]; then > echo "You currently don't have any print jobs." > echo "Exiting..." > exit 0 > else > clear > echo "Rank Owner Job File(s) > Total Size" > echo "$JOBS" > echo "" > echo -n "Enter the print Job number you want to cancel (0 to > exit)?: " > read answer > > # I think there should be a check here, after the first test > if [ "$answer" != 0 ]; then > > # the bit bucket is temporary until second check is worked out > cancel $answer > /dev/null 2>&1 > echo "Job $answer cancelled." > sleep 1 > > # an elif here if the print job ID doesn't exist > > else > echo "No print job selected. Exiting..." > fi > fi > done > > exit 0 > > Thanks for any tips! What's the output of "lpq -a" look like on your system? I'd be inclined to filter that so that you've got a list of job ids, one per line, with no other text (including whitespace) on the line, and then pipe that into 'grep -F -x "$answer" &> /dev/null', then test the exit status of the grep. Paul.