LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-28-2007, 12:48 PM   #1
yuun
LQ Newbie
 
Registered: Jul 2004
Posts: 13

Rep: Reputation: 0
basic command functionality


I'd seriously google this but I have no clue what to search for...

Is there a way to run a command within a command? Something like "mplayer (locate mp3)" or "kill -9 (pgrep firefox)"

If so, what is the syntax?

Thank you for your time!
 
Old 07-28-2007, 12:57 PM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Yeah, you can use backticks: mplayer `locate *.mp3`.
 
Old 07-28-2007, 01:02 PM   #3
zhangmaike
Member
 
Registered: Oct 2004
Distribution: Slackware
Posts: 376

Rep: Reputation: 31
Yes. It's called command substitution. You can read about it in the man page of your favorite shell.

I believe most (if not all) shells can do it, but I only know the syntax for bash. Using your own example, the following will work:

Code:
kill -9 `pgrep firefox`
kill -9 $(pgrep firefox)
kill -9 "$(pgrep firefox)"
bash has the $( ) syntax which is much better than the back tics ` ` since it can be nested or placed within quotes.

You may also want to check out the command xargs. It would probably work best for your first example:

Code:
 locate mp3 | xargs -d'\n' mplayer
EDIT: First example used to say killall instead of kill.

Last edited by zhangmaike; 07-28-2007 at 01:42 PM.
 
Old 07-28-2007, 01:02 PM   #4
yuun
LQ Newbie
 
Registered: Jul 2004
Posts: 13

Original Poster
Rep: Reputation: 0
wow! quick response!

Thanks, that was exactly what I was looking for!
 
Old 07-28-2007, 01:39 PM   #5
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 124Reputation: 124
FYI, killall takes a process name as argument, so you could just do "killall firefox".
 
Old 07-28-2007, 01:41 PM   #6
zhangmaike
Member
 
Registered: Oct 2004
Distribution: Slackware
Posts: 376

Rep: Reputation: 31
Oops... I knew that.

What an embarrassing typo.
 
  


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
basic WINE functionality mr.v. Linux - Newbie 4 04-29-2011 02:59 AM
Looking for Alternative to RHN Satellite Server basic functionality chad504 Linux - Enterprise 10 01-24-2007 11:28 AM
LXer: Review: Conglomerate XML Editor reaches basic functionality LXer Syndicated Linux News 0 01-17-2006 05:46 AM
Basic ls command cookie_ie Linux - Newbie 9 03-22-2005 06:38 PM
No touchpad features beyond basic ps/2 functionality tisource Linux - Laptop and Netbook 1 02-27-2005 03:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:59 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration