LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 09-26-2010, 05:03 PM   #1
mwesolow
LQ Newbie
 
Registered: Sep 2010
Location: Waterloo, ON
Distribution: GNU/Linux
Posts: 7

Rep: Reputation: 0
Having trouble extracting absolute directory from type command


I need to extract the absolute directory from the type command when I pass it a program name. E.g.
Code:
>type cat
cat is hashed (/bin/cat)
There is one other case (I believe):
Code:
>type lpr
lpr is /usr/bin/lpr
I thought of using regex, but it returns the whole line, not just the match. In addition, there is no option cited in the man page for type that returns just the command directory. I appreciate your help!

Note: this is part of my solution to a programming assignment in bash shell scripting.
 
Old 09-26-2010, 06:35 PM   #2
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Jessie (Fluxbox WM)
Posts: 1,387
Blog Entries: 52

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
Quote:
Originally Posted by mwesolow View Post
I thought of using regex, but it returns the whole line, not just the match.
Not sure what you are using to do the regex matching, but a command such as grep has a flag ('-o') to return only a match.

The bash regex matches also have ways of accessing the matches - have a look at the elements of BASH_REMATCH.

Last edited by neonsignal; 09-26-2010 at 06:39 PM.
 
  


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
Get the absolute path of the latest file modified on a directory mortonmorton Linux - Newbie 2 10-15-2009 10:05 PM
[SOLVED] untar backup into new directory? absolute paths in tar qwertyjjj Linux - Newbie 4 08-19-2009 04:41 PM
how to get the absolute path information of a command from ps command output ratul_11 Linux - General 1 08-06-2008 03:10 AM
What is the absolute path of mozilla component directory in RHEL 5.0 Red Hat Linux - Software 1 09-06-2007 05:48 PM
Extracting a tar ball directly into a directory kushalkoolwal Debian 2 09-28-2005 02:47 PM


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