PaperCut Blog

Tech & DevCoding

SOLVED: ‘syntax error near unexpected token `do’

SOLVED: ‘syntax error near unexpected token `do’

I’m Jason, your friendly neighborhood junior QA (Quality Assurance) here at PaperCut. This is the story about the time I solved “syntax error near unexpected token `do”.

Settle in – it’s a page-turner! Or wheel scroller. Or perhaps finger-dragger?

I had to capture a large number of example spool files on MacOS for analysis. The easiest way to do this is to:

  • pause the CUPS print queue
  • print to it
  • copy the spool file
  • resume the printer.

Given PaperCut’s a vendor neutral kind of company, I was doing this across a large number of printer and copier brands. That meant I had more than a couple of print queues (ok, I had dozens), and doing this manually was not the smart thing.

So I wrote a simple script:

# Check for disabled print queues
if [ -z $(lpstat -p | awk '/disabled/ {print $2}') ] &> /dev/null;
   	echo "\tNothing to do."
   	echo "Processing:"
   	for printer in $(lpstat -p | awk '/disabled/ {print $2}')
          	cupsenable "$printer"
          	echo "\tEnabled $printer"

Except when I ran it, I received the following error:

`home/jason/ line 10: syntax error near unexpected token `do

I’ll admit it, I spent quite a bit of time checking my syntax for errors (it’s right there in the error message!) only to find out it was my choice of text editor that caused me grief.

My primary workstation is a Windows laptop; my target machine is MacOS. When editing on Windows, I had Windows Line Endings (CR+LF) not Unix Line Endings (LF).

A quick change in Notepad++ and my script ran without problems:

Edit -> EOL Conversion -> Unix (LF)

Here’s hoping this little tip will help out future junior QAs at PaperCut and elsewhere!

We’re often on the lookout for new QAs and all sorts of tech types. Visit the PaperCut careers page to see if there’s something that takes your fancy.