Saturday, May 4, 2024
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 830  / 1 Year ago, sat, april 8, 2023, 5:26:51

I want to open the location where python is installed. To check the location I used.


whereis python | xargs -n 1 echo

output :



/usr/bin/python3.8

/usr/bin/python3.8-config

/usr/bin/python

/usr/lib/python2.7

/usr/lib/python3.8

/usr/lib/python3.9

/etc/python3.8

/usr/local/lib/python3.8

/usr/include/python3.8

Although I can copy past the location for xdg but I don't want to do it. I want to use pipe operator and open the location using xdg-open. However, there is one problem. How do I select the argument from the list above. Suppose I want to select the 3rd location. Is there any way to do it.


I thought of following but it did not work.


whereis python | xargs $3 xdg-open

More From » command-line

 Answers
1

Just filter the output before passing it to xargs:


whereis python | awk '{print $3}' | xargs xdg-open

That awk command will only print the 3rd word, so that's all you will pass to xargs. Of course, using xargs is pointless when you just have a single argument. Perhaps you want this instead?


xdg-open $(whereis python | awk '{print $3}')

Or, simply use which which will return the first occurrence of the search string in your $PATH:


xdg-open $(which python)

Note that you cannot open python with xdg-open, that's nonsensical since there is no graphical program that can usefully open a binary, let alone a binary that is a scripting language.


[#1526] Saturday, April 8, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
theurn

Total Points: 30
Total Questions: 110
Total Answers: 111

Location: Bahrain
Member since Fri, Sep 16, 2022
2 Years ago
theurn questions
Tue, Apr 5, 22, 14:18, 2 Years ago
Mon, Feb 14, 22, 16:29, 2 Years ago
Tue, Jan 10, 23, 23:59, 1 Year ago
Fri, Apr 8, 22, 01:36, 2 Years ago
;