bash question - syntax error near unexpected token
Hi,
I wrote a script like this Code:
for i in 2 3 4 5 6 7 8 9 10 do When I run #./testrun.sh I got the error ./testrun.sh: line 3: syntax error near unexpected token `/usr/bin/pdfunite' ./testrun.sh: line 3: ` /usr/bin/pdfunite test.pdf chap$i.pdf test.pdf' Do you know how to fix the error? Thanks in advance. |
try a semicolon after your last list item (before do, else bash thinks 'do' is one of the items to perform the for loop on), and another semicolon on the line before done. You also need to let bash know [i] is your variable, with $i.
Try this: Code:
for i in 2 3 4 5 6 7 8 9 10; do |
You missed a semicolon before the do keyword (plus a $ sign to evaluate the i variable inside the loop)
Code:
for i in 2 3 4 5 6 7 8 9 10; do Code:
for i in 2 3 4 5 6 7 8 9 10 |
On line 1 you either need a semicolon before " do", or "do" needs to be on its own line.
Examples: Code:
#!/bin/sh Code:
#!/bin/sh |
Thanks for the tips. I fixed the error. Now something else comes up.
I run the script and got this message: Code:
Syntax Error: Catalog object is wrong type (null) Code:
drwxr-xr-x 2 dat root 4096 Mar 25 12:11 . Code:
#!/bin/bash |
According to the pdfunite man page you can try to do it without a loop and by means of extended brace expansion:
Code:
/usr/bin/pdfunite chap{1..10}.pdf test.pdf |
As mentioned in the earlier post, I tried that and got the same error.
|
There may be problems with your PDF files.
Also, pdfunite may not work when your destination PDF file is the same as one of your source PDF files. |
Yes, Mike_M. You are right. Is there anyway I can type a command that listed chap1.pdf chap2.pdf til chap10.pdf without having to spell them out all. Thanks.
|
I'm sure there are many ways to do this, but the first that pops in to mind would be using concatenation to build your final command. Something along the lines of the following:
Code:
#!/bin/sh See colucix' answer in post #6 for the obviously better solution :) |
Very nice. I should have thought of that. Thank you very much.
|
The code previously shown by colucix does the same in a much more elegant way, provided that you use a modern shell, like Bash (most likely) or Zsh:
Code:
/usr/bin/pdfunite chap{1..10}.pdf test.pdf |
Quote:
(But note that arrays are not supported by posix-based /bin/sh scripts. Always use /bin/bash or another shell that has explicit array ability.) Code:
#!/bin/bash Since environment variables are generally all upper-case, it's recommended practice to keep your own user variables in lower-case or mixed-case to help differentiate them. Scripting With Style But finally, since the chapter files are already there, you can probably just use simple globbing instead. Code:
/usr/bin/pdfunite chap[1-9].pdf chap10.pdf "$outfile" Notice how I had to separate out chap10.pdf though, since globbing produces lists in shell sorting order. For this reason I highly recommend getting into the habit of fully zero-padding all numbers in your filenames, which will let the shell automatically sort them properly. |
All times are GMT -5. The time now is 07:01 PM. |