LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, 09: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, 09:40 PM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,732

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

Rep: Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920
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-12-2021, 11:28 PM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,869
Blog Entries: 1

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

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

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
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



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 03:35 PM
[SOLVED] Script error: "syntax error near unexpected token 'then'" RyuuzakiMasato7 Linux - Server 18 06-20-2011 09:28 AM
[SOLVED] "Error: syntax before '@' token and Error: syntax at 'OTHER' token" bullrider Programming 2 07-27-2009 08:00 AM
syntax error near unexpected token `set' `if ( $dirhome == "." ) set dirhome = `pwd dayanand patil Linux - General 6 01-21-2009 01:52 AM
syntax error unexpected token near "then" pclimmex Linux - Newbie 1 06-20-2008 10:51 PM

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

All times are GMT -5. The time now is 06:44 PM.

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