LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Having trouble extracting absolute directory from type command (https://www.linuxquestions.org/questions/linux-newbie-8/having-trouble-extracting-absolute-directory-from-type-command-834624/)

mwesolow 09-26-2010 04:03 PM

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.

neonsignal 09-26-2010 05:35 PM

Quote:

Originally Posted by mwesolow (Post 4109671)
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.


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