Thursday, May 23, 2024
7
rated 0 times [  7] [ 0]  / answers: 1 / hits: 1078  / 2 Years ago, wed, june 15, 2022, 5:11:37

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).


More From » command-line

 Answers
7

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.


[#44689] Thursday, June 16, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rinstracte

Total Points: 221
Total Questions: 114
Total Answers: 120

Location: France
Member since Fri, Jan 28, 2022
2 Years ago
rinstracte questions
Wed, Jun 15, 22, 02:09, 2 Years ago
Tue, Jan 24, 23, 01:39, 1 Year ago
Wed, Jun 9, 21, 04:34, 3 Years ago
Sun, Apr 17, 22, 11:38, 2 Years ago
;