ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I run a script, not written by me, that will take spam and report it to the various abuse addresses. Prior to my upgrade to Mandriva 2010 from 2009.1 this script was working with no issues, now however when trying to run the script I get:
/usr/local/bin/reportSpam: line 1020: syntax error near unexpected token `('
/usr/local/bin/reportSpam: line 1020: ` SUBJECT="$BASE_SUBJECT (${SPAM_IP}) $ORIGINAL_SUBJECT"'
/usr/local/bin/reportSpam: line 1022: syntax error near unexpected token `('
/usr/local/bin/reportSpam: line 1022: `## NANAS_SUBJECT="[email] (${SPAM_IP}) $ORIGINAL_SUBJECT"'
Removed the parens on line 1022 and get:
/usr/local/bin/reportSpam: line 1092: unexpected EOF while looking for matching `)'
/usr/local/bin/reportSpam: line 1243: syntax error: unexpected end of file
Line 1092 being:
BAD_ADDRS="$(
and there is no line 1243. As I said in my original post this script used to work fine before I upgraded to Mandriva 2010 so something must have changed somewhere but I'll be darned if I can figure it out. I know very little about scripts.
Well, it did work, but there was another problem. This one is more interesting, it looks bash's parser fails when faced with a here document piped to command with spaces in it when that is inside a $() substitution. The bash version here is
4.0.28(1)-release, perhaps bash 3.x does not have this problem, which is why the upgrade caused you problems. dash appears to handle this just fine.
Anyways, here is a workaround:
Code:
# change the following lines (1092, 1093)
BAD_ADDRS="$(
cat <<-EOF | fold -s -w 64
# to this
fold_s_w64() { fold -s -w 64; }
BAD_ADDRS="$(cat <<-EOF | fold_s_w64
I was thinking you would apply gaurav1086's fix in addition to mine. Although looking at the script again now, I can't actually see why having parens in a string would be a problem.
Is it possible to install bash 3.x? That would probably be the easiest way to run this script.
I've currently got all the changes suggested made to the script, still I get the line 1020 error. Bash reports version
bash --version
GNU bash, version 4.0.33(2)-release (i586-mandriva-linux-gnu)
not sure if I could downgrade to verson 3 though.
I've got dash installed however haven't had a chance to read the manpage. running [chris@localhost ~]$ dash
$ reportSpam
then entering the script name also gives me the same line 1020 error though I may not be doing this correctly. Will have to print out the manpage and look it over.
I've currently got all the changes suggested made to the script, still I get the line 1020 error.
Oh, from your earlier post I assumed that the 1020 error was fixed. Unfortunately I can't reproduce this error in a small script (can't run the whole script because it depends on other things in your system), so I have no idea why it's occuring.
To run the script with dash do
Code:
$ dash $(which reportSpam)
I assume reportSpam is in your PATH. I don't think dash will be able to run the script as it has less features than bash (eg: doesn't support arrays). I just mentioned it because dash doesn't have a problem with the syntax used on line 1092 (I was able to reproduce that problem in a small script).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.