Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

Questions tagged [which]

The unix command "which" is commonly used to search for an executable in the PATH, even though it is not very good at this job.

Filter by
Sorted by
Tagged with
0 votes
0 answers
14 views

I have a situation in which "which -a python" is not showing execution order when run on CentOS 6 with Python 3.7 [duplicate]

Does anyone know where to begin with debugging this? [chuck@vmlnx-tacx32 openssl-1.1.0h]$ which -a python /usr/local/bin/python /usr/bin/python [chuck@vmlnx-tacx32 openssl-1.1.0h]$ /usr/local/bin/...
user avatar
  • 141
2 votes
2 answers
1k views

sh: which: line 1: syntax error: unexpected end of file; sh: error importing function definition for `which'

We are running: Red Hat Enterprise Linux release 8.5 (Ootpa). We allow the server to update weekly using "yum -y update". We recently began receiving the following errors when executing ...
user avatar
  • 161
0 votes
1 answer
49 views

Where is the executable?

I have this command that I run. Let's call it foo. I can execute foo without specify the full path to foo like so: $ foo missing args I suspect foo is a bash script so I want to look at the source ...
user avatar
  • 2,103
0 votes
1 answer
55 views

What is which command output ordering? [closed]

In bash I see which returns the paths in order, but in zsh it has different ordering. I now primarily use zsh, how can I get proper output ordering of which in zsh? Why is it different? I expected the ...
user avatar
0 votes
1 answer
84 views

output of which perl is /bin/perl instead of /usr/bin/perl

Hi I'm running Redhat Server 7.9 and running into an interesting issue. If I type which perl, I get /bin/perl, but it should be /usr/bin/perl. The same for git. This same machine would print /usr/ ...
user avatar
6 votes
5 answers
1k views

IFS=',' /usr/bin/read vs IFS=',' read

Context $ bash --version GNU bash, version 4.4.19(1)-release (x86_64-redhat-linux-gnu) Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/...
user avatar
  • 61
2 votes
2 answers
313 views

What's the difference between two uname files

I have to find the uname file on a Debian machine, check from which package it is and delete it. When I use which to find it, I get /usr/bin/uname. When I try to check it by dpkg -S uname there is no ...
user avatar
0 votes
1 answer
54 views

command -v <foo> returns wrong result after overwriting <foo> as function

I have the following functions in my .bashrc which just creates a python project with venv and creates gitignore and readme, after I initialise with git as: git init python ...
user avatar
1 vote
1 answer
697 views

"which" command not work in shell script with #!/bin/bash but work with #!/bin/zsh [duplicate]

I have a sh file: #!/bin/bash echo $PATH date pwd which nano First three lines work with both #!/bin/bash and #!/bin/zsh but I got a ./script.sh: line 5: which: command not found with bash, but zsh ...
user avatar
  • 113
1 vote
1 answer
34 views

adding script to which command

I have a script/tool in linux /full/path/here/grabber. I want to know how I will be able to use which on it. So every time i want to use it, I can just execute grabber instead of having to call its ...
user avatar
1 vote
1 answer
57 views

Which binary would be run when we have multiple installations?

I wanted to set gsettings as /usr/bin/gsettings so I created an alias. But I am not sure if that works: $ type gsettings gsettings is aliased to `/usr/bin/gsettings' gsettings is /home/linuxbrew/....
user avatar
  • 1,374
0 votes
0 answers
23 views

Why same paths are shown when running `which -a` command [duplicate]

When I run which -a psql the result shows three same paths. /usr/local/bin/psql /usr/local/bin/psql /usr/local/bin/psql I can run the command psql without a problem. I just want to know why this ...
user avatar
  • 4,525
1 vote
0 answers
23 views

The command `which` does not show the path of command correctly [duplicate]

My system is RHEL 7.5 and the output of vim --version as below: me@localhost:~/tmp$ vim --version VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Aug 9 2019 03:17:15) I want to use vim 8 so I ...
user avatar
  • 2,819
0 votes
1 answer
169 views

How to map to a different binary for the same program on linux/mac?

Suppose which R returns /opt/anaconda3/bin/R, and suppose I have other R binaries in other locations, and I want a different R binary to run when I type R. How can I make that happen without ...
user avatar
  • 141
2 votes
0 answers
328 views

whereis Gstreamer - located in two paths - causing issues

Gstreamer doesn't run as expected when executed from the command line. It turns out all the plugins I am installing are defaulting to one location while when I'm running gstreamer its opening from ...
user avatar
0 votes
1 answer
167 views

command invocation location is inconsistent with `which` command output

I'm installing protocolbuf on my CentOS 7 box, and after installation, I saw some inconsistency while running the protoc compiler binary: $ which protoc /usr/local/bin/protoc $ protoc bash: /bin/...
user avatar
  • 103
5 votes
2 answers
1k views

"which" can't find location of executable even though it runs

Background I log into a server to do scientific computations. It runs 'Scientific Linux version 7.4'. In order to get access to different software I have to run a command like 'module load x'. For ...
user avatar
  • 151
1 vote
1 answer
90 views

What is the difference between `which <command>` and `command -v <command>`?

When I put in which npm, I get /usr/local/bin/npm. When I put in command -v npm, I get /usr/bin/npm. Why is that? What's the difference? man which says which "returns the pathnames of the filenames ...
user avatar
0 votes
1 answer
41 views

How can "which" find commands inside directories where I have no read permissions?

On my work PC, I noticed that the which command seems to be able to find executables in directories, that I have no read permissions for. $ export PATH=/usr/sbin:$PATH $ ls /usr/sbin ls: cannot open ...
user avatar
  • 189
2 votes
2 answers
118 views

Why is the which command so hard to eradicate? [closed]

I'm coming from places like Why not use "which"? What to use then? and https://stackoverflow.com/questions/592620/how-to-check-if-a-program-exists-from-a-bash-script and am myself a long-...
user avatar
  • 6,929
0 votes
1 answer
52 views

POSIX command for `which --all`, to list all on PATH not just first?

Many shells have an --all flag to which: --all, -a Print all matches in PATH, not just the first But which is not POSIX-compliant; shellcheck points us at command -v. command however has ...
user avatar
  • 1,588
0 votes
1 answer
187 views

Why is `which <command>` not picking up aliases? [duplicate]

I'm on OSX and if I run python --version in a bash shell, I get this: $ python --version Python 3.7.3 But the which python command appears to be pointing to version 2.7. $ which python /usr/local/...
user avatar
  • 2,853
1 vote
3 answers
112 views

How do I control which command is when i type python in the shell

I use anaconda as a way to handle virtual environments. This means I have multiple version of python installed. I experience that the wrong python version starts when I run python from the shell. ...
user avatar
0 votes
2 answers
384 views

Syntax error near unexpected token 'which'

I'm trying to script something in OS X Automator and i ultimately want to send the output of which npm to <npm> install and i'm getting the error Syntax error near unexpected token 'which' Any ...
user avatar
  • 75
0 votes
2 answers
398 views

content from pwd and which failed with sed to be replaced [duplicate]

I have a file which has the following content: BWA='/software/bwa/bwa-0.7.12/bwa' SAMTOOLS='/software/samtools/samtools-1.3.1/samtools' The above tools are on my computer: which bwa => /work/...
user avatar
0 votes
0 answers
550 views

Symbolic link to python 3.6 is ignored

How can the following be? dims@pterosaur:~$ ls -l /usr/local/bin/python3 lrwxrwxrwx 1 root root 18 Aug 15 12:18 /usr/local/bin/python3 -> /usr/bin/python3.6 dims@pterosaur:~$ which python3.6 /usr/...
user avatar
  • 2,515
1 vote
1 answer
1k views

Why can't I which pushd

I've been using pushd and popd for a long time while writing bash script. But today when I execute which pushd, I get nothing as output. I can't understand this at all. I was always thinking that ...
user avatar
  • 2,819
1 vote
1 answer
66 views

Which is not searching full $PATH

If I run sudo which abc I would expect it to search the superusers $PATH for the program 'abc', but it looks like it only searches a subset. I can see this by running sudo echo $PATH and comparing ...
user avatar
  • 113
1 vote
1 answer
97 views

Installing command line tool if it's not in the PATH

I have this bash function which I am trying to use to install a command line tool if it's not already in the PATH: ncf(){ if ! type -f ncf &> /dev/null || ! which ncf &> /dev/null; ...
user avatar
-1 votes
1 answer
576 views

Command which do not locate the real path of command

We have a RHEL 7.x with Hortonworks (HDP) installed and need an advice why we get on which command: no hadoop in ... The Hadoop client is installed under /usr/bin and from env we get [root@...
user avatar
  • 11k
3 votes
1 answer
437 views

Why is the "wrong" executable being run? [duplicate]

I am trying to run ipython from the bash (version 4.4.19) command line. As a Python developer, I have various installations of ipython at various versions in various virtualenvs' paths, and so it is ...
user avatar
  • 498
0 votes
1 answer
475 views

how is it possible that which -a shows two paths?

When I execute which -a python I get two paths: /home/autumn/anaconda3/bin/python /usr/bin/python If I delete the directory ~/anaconda3 the first link to the python binary automatically vanishes....
user avatar
4 votes
0 answers
131 views

"which" command doesn't match program being executed [duplicate]

I was trying to install a newer version of curl and when I ran: curl -V, the version number didn't change. After running which curl, it displayed the path of the newly installed version: /usr/local/...
user avatar
  • 41
1 vote
0 answers
213 views

Which and whereis fail to find command?

Why is it sometimes that which and whereis fail to find a command? e.g. $ awswl -bash: /Users/geoffrey/Library/Python/2.7/bin/awswl: No such file or directory $ which awswl $ whereis awswl $ I ...
user avatar
2 votes
1 answer
411 views

Command 'which' not showing output for custom PATH locations

Scenario I have a ProductivityScripts project on GitHub, and when I install Linux (Debian 9), I add this folder to PATH for ease of use. I.e., I add the following line to ~/.bashrc: export PATH="~/...
user avatar
  • 477
0 votes
1 answer
83 views

Why does gnu which show a script instead of a file path

I encounterd the following output while using which [user@localhost ~]$ which gem gem () { \typeset result; ( \typeset rvmrc; rvm_rvmrc_files=("/etc/rvmrc" "$HOME/.rvmrc"); if [[ -n ...
user avatar
  • 1,084
16 votes
2 answers
6k views

how is whence different than which? [duplicate]

I read `which`, but all but I cannot really get the difference. I am running zsh 5.4.2 on 64-bit debian-buster. Both which and whence are shell-builtins . Can people point out where whence would be ...
user avatar
  • 10.8k
1 vote
2 answers
562 views

`which` for SunOS 5.10 [duplicate]

I have (normal user) access to a SunOS 5.10 machine. /usr/bin/which is broken (it blocks). Clearly something is wrong on the system, but not having root access limits drastically what I can do. I ...
user avatar
  • 29.7k
3 votes
2 answers
449 views

How to use which command in Crontab?

I would like to make crontab run this script as a regular user: #!/usr/bin/env bash PIDFILE=wp-content/uploads/sphinx/var/log/searchd.pid if ! test -f ${PIDFILE} || ! kill -s 0 `cat ${PIDFILE}`; ...
user avatar
  • 217
1 vote
1 answer
508 views

Why doesn't "export" overwrite existing values?

Why isn't export python=/usr/local/bin/python2.7 changing the path to python? I am baffled by the following: $ which python /usr/bin/python $ export python=/usr/local/bin/python2.7 $ which python /...
user avatar
  • 2,853
1 vote
2 answers
534 views

how do I get the 'which' command to resolve symlinks?

I've symlinked a script file into my ~/bin, and when I do which foo the output is: /Users/me/bin/foo Is there a way to have this resolve the symlink and show me the real file?
user avatar
  • 7,317
0 votes
1 answer
51 views

Command run is not the one returned by the command `which` [duplicate]

$ which doxygen /home/gauthier/bin/doxygen $ $(which doxygen) -v 1.8.13 $ doxygen -v 1.8.11 # <- ??? $ doxygen error: Doxyfile not found and no input file specified! Doxygen version 1.8.11 ...
user avatar
  • 820
2 votes
1 answer
179 views

Linux/bash does not execute the executable that "which" tells me [duplicate]

Observation: I have an executable named foo, located in /b/foo. It is compiled against an old header of a dynamic library, causing it to segfault when executed: $ foo Segmentation fault. // Expected ...
user avatar
1 vote
1 answer
1k views

Why I cannot find (using which) usermod as a regular user in RHEL7

Any ideas why the which command is unable to find the usermod command in rhel 7. Here is what I did (and corresponding output) [ec2-user@ip-10-0-4-109 ~]$ echo $PATH /usr/local/bin:/usr/bin:/usr/...
user avatar
0 votes
1 answer
118 views

basic linux executable path does not show up [duplicate]

I am trying to find the path of basic commands like ls or cd using which command. I see the path for ls but not for cd. Of course both the commands work fine. Any idea? $ which ls /bin/ls $ which cd $...
user avatar
  • 1
45 votes
2 answers
9k views

Bash remembers wrong path to an executable that was moved/deleted

When I do which pip3 I get /usr/local/bin/pip3 but when I try to execute pip3 I get an error as follows: bash: /usr/bin/pip3: No such file or directory This is because I recently deleted that ...
user avatar
1 vote
1 answer
1k views

Shell script for kill command

I'm following a tutorial on using text editors and one exercise was to make a "safer" kill command script. I made a ~/bin directory. Then made the following kill command script called ekill. #!/bin/...
user avatar
0 votes
1 answer
58 views

Correcting the installed path in MacOSx

I have installed a software in my MacOsX called Plumed as a prerequisite for another software called GROMACS. Process of installation for Plumed is pretty standard. ./configure --prefix=Users/...
user avatar
  • 129
0 votes
2 answers
81 views

Command which that isn't in norm

I have this example cp `which mv` rename In instruction of my homework is, that this command isn't in norm and replace the command with different example that does do exactly the same. My question ...
user avatar
  • 129
2 votes
3 answers
2k views

Where is `exit` defined?

Suppose I want a bash command to do something extra. As a simple example, imagine I just want it to echo "123" before running. One simply way to do this would be to alias the command. Since we ...
user avatar