Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I answered this question but realize that it could be better.

How can I convert:

$ which gjslint
$ cat /usr/local/bin/gjslint

Into something like this:

$ cat < which gjslint
-bash: which: No such file or directory

..so that the output path+filename from which is passed onto cat which then does it's thing (i.e. printing the contents of the filename to the screen).

share|improve this question
    
Funny, your answer on SO has been updated a minute after I posted mine. –  Lekensteyn Jun 10 '11 at 21:02
    
Not sure what you mean, but my intent was to learn, improve my answer on SO, and thus asked a question on AskUbuntu. –  Zabba Jun 10 '11 at 21:23
add comment

1 Answer 1

up vote 7 down vote accepted

Use backticks:

cat `which gjslint`

If the path contains whitespace (unlikely with default paths), you need to put it in parentheses:

cat "`which gjslint`"

An alternative would be cat "$(which gjslint)". The reason I use backticks instead of $() is because it's easier to type, two keystrokes with one hand vs 4 keystrokes with two hands. I am aware of the disadvantages of using ` over $(), but those do no apply in this case. You're not going to nest backticks or use slashes for quickly finding a program.

share|improve this answer
2  
There is an argument that $(which gjslint) is preferable. I can't personally speak for validity of this particular argument, but I do tend to trust the content of the site it was posted on. –  ændrük Jun 10 '11 at 21:07
    
Updated why I use backticks instead of $(). –  Lekensteyn Jun 10 '11 at 21:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.