5

I am trying to run openscad from the command line and it throws an error, but if I type out the whole path reported by which it seems to work as shown below.

[dataproc@Euclid ~]$ which openscad
/usr/bin/openscad
[dataproc@Euclid ~]$ openscad
bash: /usr/local/bin/openscad: No such file or directory
[dataproc@Euclid ~]$ /usr/bin/openscad
[dataproc@Euclid ~]$ #this worked

I am totally clueless as to what is going on here, any help would be greatly appreciated.

2 Answers2

6

which lies; it can report things based on an idealized situation as gleaned from your shell startup files, while missing some possibilities and not catching any changes not made by the standard files. Use type to see what the shell really thinks is going on.

2@mress:1 B$ type which
which is /usr/bin/which

External commands simply can't tell what will really happen, because they have to guess at functions and aliases based on your startup files and won't know about things created by autoload mechanisms; you need to ask the shell itself what it will do.

2@mress:2 B$ type type
type is a shell builtin
geekosaur
  • 11,723
  • 32
  • 40
  • Everything you wrote is correct, but didn't answer why his bash returning for the simple "openscad", "/usr/local/bin/openscad: No such file or directory". –  May 28 '11 at 07:12
  • @kobame: neither I nor anyone else can know the answer without knowing the output of `type openscad`. Which is what I tried to explain; apparently I failed. – geekosaur May 28 '11 at 07:16
  • [dataproc@Euclid ~]$ type openscad openscad is hashed (/usr/local/bin/openscad) –  May 28 '11 at 14:54
  • I am not sure what "openscad is hashed" means but there was no alias for the command. Thank you all for the quick response. –  May 28 '11 at 14:54
  • @shawn: Run `hash -r` and then `type openscad` again. Looks like it may have been in `/usr/local/bin`, got moved, and the shell didn't update its internal location hash. – geekosaur May 28 '11 at 14:56
  • @shawn: Most shells keep a hash table mapping a hashed version of a simple command to a full pathname, because full `$PATH` searches are fairly expensive when you're a shell and running those commands is your main function. The `hash` command can be used to manipulate this table. – geekosaur May 28 '11 at 14:58
  • Thanks geekosaur that worked, I will read up on this hash command a bit more and hopefully be able to recognize what is going on next time. –  May 28 '11 at 14:58
  • @geekosaur Nice explanation! thanx. One question: when (and how) bash updating his hash table? So when i install a new version o any command to the another dir in PATH and after delete it - when got hash table updated? –  May 28 '11 at 16:50
  • @kobame: I don't know the specific rules for `bash`. Some shells periodically check the modification time on directories in `$PATH`; some don't ever seem to update themselves. I've simply developed the habit of always doing `hash -r` after making any changes to a directory in `$PATH` (installing, removing, or moving programs etc.). – geekosaur May 28 '11 at 17:33
  • I think it only needs to be run when you had something in your path that you manually delete and replace with something in a different directory also in the path. I have been using bash for quite a while and this is the first time I have ever run into such a problem. –  May 28 '11 at 21:51
0

Without knowing your .profile (.bashrc, etc) only guessing, than you have somewhere

alias openscad=/usr/local/bin/openscad

and that is why your bash trying run /usr/local/bin/openscad and not the default one in /usr/bin.

clt60
  • 867
  • 1
  • 9
  • 24