Perl Syntax Error Near Unexpected Token
Contents |
Q&A Tutorials Poetry RecentThreads NewestNodes Donate What'sNew on May 20, 2012 at 16:55UTC ( #971498=perlquestion: print w/replies, xml ) Need Help?? vit has asked for the wisdom of the perl system syntax error near unexpected token (' Perl Monks concerning the following question: Dear Monks, I want to
Sh: -c: Line 0: Syntax Error Near Unexpected Token `(' Perl
match with optional "'" and optional subsequent word cat file.txt | perl -ne '{chomp; ($a, $b) = " syntax error near unexpected token `('" bash split/\s+/; $s = "$a $b"; + next if($s !~ /^\w+\'?\w+?\s+\w+\'?\w+?$/); print "$_\n"}' | wc -l [download] I am getting bash: syntax error near unexpected token `)' [download] Is it something related to sygwin or activesatate Perl I use? Or I am missing something?Comment on syntax error near unexpected token `)'Select or Download Code Replies are listed 'Best First'. Re: syntax error near unexpected token `)' by zwon (Monsignor) on May 20, 2012 at 17:03UTC It is something related to bash in fact. See QUOTUNG section in the manual: Enclosing characters in single quotes preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash.[reply] Re^2: syntax error near unexpected token `)' by vit (Pilgrim) on May 20, 2012 at 17:05UTC Then how to handle a single quote match? [reply] Re^3: syntax error near unexpected token `)' by zwon (Monsignor) on May 20, 2012 at 17:17UTC This sounds more like a bash question to me, but you can replace single quotes with \N{APOSTROPHE} or \x27. In bash you can do it like this: $ echo 'aa'"'"'bb'; aa'bb [download] [reply][d/l][select] Re^4: syntax error near unexpected token `)' by ikegami (Pope) on May 21, 2012 at 02:24UTC Re: syntax error near unexpected token `)' by tobyink (Abbot) on May 20, 2012 at 17:05UTC Seems like a shell quoting issue rather than a Perl one. Try putting your script into a file rather than using the "-e" argument. perl -E'sub Monkey::do{say$_,
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up syntax error near unexpected token `|' Perl code up vote 0 down vote favorite I am trying to execute this in my perl script my $command = `ps -p $pidnumber | wc -l`; but when I run http://www.perlmonks.org/?node_id=971498 the script it show me something like this: sh: -c: line 1: syntax error near unexpected token `|' sh: -c: line 1: ` | wc -l' Which would it may to be the error? perl shell fedora share|improve this question edited Apr 2 '13 at 17:06 toolic 30.6k43468 asked Apr 2 '13 at 17:04 Davico 304 8 Where is $pidnumber coming from? Might it have a newline appended to it? –RickF Apr 2 '13 at 17:13 add a comment| 3 Answers http://stackoverflow.com/questions/15770014/syntax-error-near-unexpected-token-perl-code 3 active oldest votes up vote 1 down vote Does $pidnumber end with a new line? See the chomp function. share|improve this answer answered Apr 2 '13 at 17:16 mob 78.7k10103221 add a comment| up vote 1 down vote try print before execute the command, because $pidnumber may have something strange: my $command_str = "ps -p $pidnumber | wc -l"; print $command_str, "\n"; my $command = qx!$command_str!; as @mob said, use chomp if newline appears in the print sentence. share|improve this answer answered Apr 2 '13 at 17:54 Miguel Prz 11.3k1530 use Data::Dumper; local $Data::Dumper::Useqq = 1; print(Dumper($command_str)); for more useful at finding oddities, especially trailing newlines. –ikegami Apr 3 '13 at 4:55 add a comment| up vote 1 down vote I agree with the other answers that an extra newline before the pipe is quite possibly the cause But the command doesn't really need the pipe! force the quoted command to return it's value as a list and then get the length of the list and you've got the wc -l "line count" my $command_str = "ps -p $pidnumber"; my $linecount = () = qx!$command_str!; share|improve this answer answered Apr 2 '13 at 18:47 Vorsprung 13.3k21232 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting yo
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and http://stackoverflow.com/questions/7383957/why-wont-this-example-from-learning-perl-6th-edition-run policies of this site About Us Learn more about Stack Overflow the http://www.linuxquestions.org/questions/programming-9/bash-syntax-error-near-unexpected-token-%60-'-818825/ company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes syntax error a minute: Sign up Why won't this example from 'Learning Perl 6th Edition' run? up vote 1 down vote favorite I am stuck on chapter 2 exercise 2 page 42 of Learning Perl 6th Edition. I copied the code example for the problem from page 296. I am using Perl version 5.10.1 on Ubuntu 11.04. I get errors that I cannot figure syntax error near out could someone please help? I will list the code and the error message below. #!/usr/bin/perl -w $pi = 3.141592654; print "What is the radius? "; chomp($radius =
HCL Search Reviews Search ISOs Go to Page... LinuxQuestions.org > Forums > Non-*NIX Forums > Programming [SOLVED] bash: syntax error near unexpected token `(' User Name Remember Me? Password Programming This 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. Are you new to LinuxQuestions.org? Visit the following links: Site Howto | Site FAQ | Sitemap | Register Now 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. Introduction to Linux - A Hands on Guide This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter. For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own. Click Here to receive this Complete Guide absolutely free. Search this Thread 07-09-2010, 12:16 AM #1 rc5gd LQ Newbie Registered: Jul 2010 Posts: 3 Rep: bash: syntax error near unexpected token `(' Hi all, I am new to this forum. I am sorry if this is not correct place to post this. I was trying to run small shell script, but could not run. I got the error like in subject. Can any one help me to figure this problem. This is exact way i was trying to do. [mycom7] # ./ctopo.sh um_test1 [(1,2),(2,1)] bash: syntax error near unexpect