LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
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


Reply
  Search this Thread
Old 10-12-2021, 10:08 PM   #1
M4xx1m1l14nn
LQ Newbie
 
Registered: Mar 2021
Posts: 10

Rep: Reputation: Disabled
"syntax error near unexpected token"


Trying to write a function such that all instances of a particular process are automatically killed. This triggers the aforementioned error:

Code:
clean_up_beam(){
	list_of_pids=`pidof (beam.smp)`

	for pid in $list_of_pids; do
	    sudo kill -9 $pid
	done
}
How do I make this work?
 
Old 10-12-2021, 10:40 PM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.8.2003
Posts: 5,475

Rep: Reputation: 2100Reputation: 2100Reputation: 2100Reputation: 2100Reputation: 2100Reputation: 2100Reputation: 2100Reputation: 2100Reputation: 2100Reputation: 2100Reputation: 2100
Suggest pkill to kill jobs by name. See man pkill.
 
2 members found this post helpful.
Old 10-12-2021, 10:57 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 22,081

Rep: Reputation: 4441Reputation: 4441Reputation: 4441Reputation: 4441Reputation: 4441Reputation: 4441Reputation: 4441Reputation: 4441Reputation: 4441Reputation: 4441Reputation: 4441
The correct syntax is:
pidof program

No (), see man pidof pages.

list_of_pids=$(pidof beam.smp)
 
1 members found this post helpful.
Old 10-13-2021, 12:28 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,224
Blog Entries: 1

Rep: Reputation: 1585Reputation: 1585Reputation: 1585Reputation: 1585Reputation: 1585Reputation: 1585Reputation: 1585Reputation: 1585Reputation: 1585Reputation: 1585Reputation: 1585
Code:
killall -9 beam.smp
Or if it is actually (beam.smp):
Code:
killall -9 '(beam.smp)'

Last edited by NevemTeve; 10-13-2021 at 12:35 AM.
 
1 members found this post helpful.
Old 10-13-2021, 01:09 PM   #5
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,431
Blog Entries: 4

Rep: Reputation: 3375Reputation: 3375Reputation: 3375Reputation: 3375Reputation: 3375Reputation: 3375Reputation: 3375Reputation: 3375Reputation: 3375Reputation: 3375Reputation: 3375
Underlying all language implementations is a thing called a "parser," which is following a pre-programmed "map" of sorts (a grammar ...) in order to try to interpret your source code. Well, grammar-designers do try to provide meaningful error-messages, but sometimes the parser just "falls down on its face, leaving lots of junk scattered all across the floor." Just like it did here.

Look very carefully at your source-code to try to spot the error.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
"Line 7 : syntax error near unexpected token ')' and Line 7: "option 1-?")" tiffney2018 Linux - Newbie 5 05-07-2016 04:35 PM
[SOLVED] Script error: "syntax error near unexpected token 'then'" RyuuzakiMasato7 Linux - Server 18 06-20-2011 10:28 AM
[SOLVED] "Error: syntax before '@' token and Error: syntax at 'OTHER' token" bullrider Programming 2 07-27-2009 09:00 AM
syntax error near unexpected token `set' `if ( $dirhome == "." ) set dirhome = `pwd dayanand patil Linux - General 6 01-21-2009 02:52 AM
syntax error unexpected token near "then" pclimmex Linux - Newbie 1 06-20-2008 11:51 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration