2

I have a program called f in my $PATH, I can simply execute it by typing f into a terminal. However, typing which f into that same terminal afterwards, it errors out: which: no f in (...), and it gives the full path in brackets (which indeed contains the correct path for f itself).

Using type f however I get the correct result.

Does anyone have an idea why that is the case?


Here are the answers to questions from the comments:

  • f itself is a symlink to a perl script:

    vwos3xz@vwososuvs012:~$ls -l $(command -v f)
    
    lrwxrwxrwx 1 root root 42  2. Aug 2012  /tef/tegf/06_CAE_System/064_soft/PERL_SCRIPTE/bin/f -> ../CRASH_SCRIPTE/FEMSTARTER/fem-starter.pl
    

    In fact, fem_starter.pl itself is a symlink to fem_starter-1.77.pl in the same directory

  • I'm reasonably sure there's no typo in the path because I can simply type f in a terminal and have it run (also, type and command -v work).

  • I set the path in .bashrc, but .bash_profile exists and just sources .bashrc. Also, I have BASH_ENV set to my .bashrc.

  • type f returns f ist /tef/tegf/06_CAE_System/064_soft/PERL_SCRIPTE/bin/f, and command -v returns /tef/tegf/06_CAE_System/064_soft/PERL_SCRIPTE/bin/f. Also, type -a f returns the same as type f.

  • "Have you opened a new window?"... do you mean a new terminal? I did, but that did not make a difference. I used both xterm and konsole, and I did start each from the window manager as well as from another xterm. Everytime, the $PATH was correctly set, but which did not work as expected.

Wolph
  • 78,177
  • 11
  • 137
  • 148
PhilippFrank
  • 143
  • 1
  • 4
  • 1
    Try `type which`. See also http://stackoverflow.com/a/677212/2908724 – bishop Jan 14 '16 at 14:44
  • It's surprising that which is not a builtin, as I simply assumed. Also, which not doing what it should is surprising. Do you have any idea why that's the cause? I have weird path issues to sort out, and that's sort of the only lead I have... – PhilippFrank Jan 14 '16 at 14:52
  • 2
    What OS (`uname -a`)? What is the result of `type which`? Please show the full output of all commands you've tried. – bishop Jan 14 '16 at 15:07
  • 1
    Without more information, the best we can do is close this as a duplicate of SO 677212. What type of command is `f`? Where is it stored? Are you sure there isn't a typo in your PATH? What is the correct result? Can you make an MCVE ([How to create a Minimal, Complete, and Verifiable Example?](http://stackoverflow.com/help/mcve))? I recognize that in this case, it may be hard to create an operational MCVE. Have you tried creating a new window? Do you set your PATH in your `.profile` (`.bash_profile`) or in `.bashrc`? What does `type f` say? What does `command -v f` say? – Jonathan Leffler Jan 14 '16 at 15:09
  • What does `type -a f which` say? – Etan Reisner Jan 14 '16 at 15:23
  • 1
    @PhilippFrank _which not doing what it should is surprising._ It's surprising to me that `which` is so popular, given that it is not (and never has been) part of any standard, unlike [command](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/command.html), [type](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/type.html) and [hash](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/hash.html). What I mean is, whatever is it that `which` _should do_, no standards body has ever agreed upon. – kojiro Jan 14 '16 at 15:36
  • What filesystem is the perl file stored on? – rici Jan 14 '16 at 15:50
  • Did you look at the file to see if there is a CRLF line ending? 'Command not found' can mean either the script itself, or the command nominated in the shebang line. – Jonathan Leffler Jan 15 '16 at 04:20

0 Answers0