Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 09-26-2010, 05:03 PM   #1
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.
>type cat
cat is hashed (/bin/cat)
There is one other case (I believe):
>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
Senior Member
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Stretch (Fluxbox WM)
Posts: 1,389
Blog Entries: 52

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
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.


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 > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:35 AM.

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