The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   UNIX - Newcomers (http://hintsforums.macworld.com/forumdisplay.php?f=15)
-   -   executables not found in path (http://hintsforums.macworld.com/showthread.php?t=6069)

windlaser 09-30-2002 08:49 PM

executables not found in path
 
I am using tchs
Let's say my user name is johndoe
I have in my .login the following:

setenv PATH "~/bin:/usr/local/bin:$PATH"
----

When I issue the command:
echo $PATH

I get:

/Users/johndoe/bin:usr/local/bin:/bin:/sbin/usr/bin:usr/sbin

---

I put an executable (call it xyzcommand) in my ~/bin directory.

while I'm in my ~/ directory (or any other directory that's NOT ~/bin) I type the xyzcommand and I'm told xyzcommand cannot be found.

if I type ~/bin/xyzcommand it works fine.

the directory IS IN THE PATH yet the commands in that directory are not found.

any clues?

houchin 09-30-2002 09:07 PM

tcsh does some kind of caching of the names of executables. I assume that this makes it faster to get to stuff.

If you give it a commandname without a path (like "xyzcommand"), it looks in its cache to determine where the actual file is. If you give it a command with a path (partial or full) (like "~/bin/xyzcommand" or "./xyzcommand") it just goes and runs the specified file.

To get tcsh to rescan your path directories for new commands, type "rehash"

windlaser 09-30-2002 09:12 PM

Thanks for the quick reply. I had already tried the rehash command. Still no good. It's very strange.

houchin 09-30-2002 09:14 PM

Are you sure the executable has execute permissions?

windlaser 09-30-2002 09:20 PM

Yup, checked that. It has x in all.

To be sure, I copied the command to the /usr/local/bin directory, executed rehash, and the executable executed from anywhere.

I did a 'which xyzcommand' to see which one it was executing: it was executing the /usr/local/bin one.

I deleted the one in /usr/local/bin and tried again. Nothing. It doesn't see it.

windlaser 09-30-2002 09:23 PM

Now this is interesting. I tried it from a bash shell and it worked fine. The plot thickens...

mervTormel 09-30-2002 10:30 PM

sheesh!
 
why all the trickery with the real name hiding? why not copy pertinent input and output results directly from the shell? if you had done that, this thread may be only two posts long!

if you're going to hand craft the symptoms here, well, then all bets are off for analyzing your issues. it's not that i don't trust you; it's that i don't trust you.

remove your command from /usr/local/bin/

show us:

% echo $PATH

% ls -l ~/bin/commandname

% which commandname

c'mon!

windlaser 09-30-2002 11:00 PM

As ORDERED:

[Mike-Whitlaws-Computer:~] mikewhitlaw% echo $PATH
/Users/mikewhitlaw/bin:/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin
[Mike-Whitlaws-Computer:~] mikewhitlaw% ls -l ~/bin
total 8
-rwxr-xr-x 1 mikewhit staff 41 Sep 30 22:58 tester
[Mike-Whitlaws-Computer:~] mikewhitlaw% which tester
tester: Command not found.
[Mike-Whitlaws-Computer:~] mikewhitlaw% ~/bin/tester
Why can't I be seen?
[Mike-Whitlaws-Computer:~] mikewhitlaw% cat ~/bin/tester
#!/bin/bash
echo "Why can't I be seen?"

[Mike-Whitlaws-Computer:~] mikewhitlaw%

hayne 09-30-2002 11:41 PM

more things to check
 
Three things to check (and report back here):
1)
To confirm what shell you are using, please do:
echo $SHELL

2)
You've shown us that /Users/mikewhitlaw/bin is in your path.
You've shown us that the 'tester' script is in the directory ~/bin
But you haven't shown us that ~/bin is /Users/mikewhitlaw/bin
How about doing:
echo ~/bin

3)
You've shown us that 'which tester' doesn't find it.
But which version of 'which' are you using?
Try doing:
which which
And please also show us what you get when you just try to execute the 'tester' program from the shell. I.e. show us the result of doing the following command:
tester

windlaser 09-30-2002 11:49 PM

[Mike-Whitlaws-Computer:~] mikewhitlaw% echo $SHELL
/bin/tcsh
[Mike-Whitlaws-Computer:~] mikewhitlaw% echo ~/bin
/Users/mikewhitlaw/bin
[Mike-Whitlaws-Computer:~] mikewhitlaw% which which
which: shell built-in command.
[Mike-Whitlaws-Computer:~] mikewhitlaw% tester
tester: Command not found.
[Mike-Whitlaws-Computer:~] mikewhitlaw% ~/bin/tester
Why can't I be seen?
[Mike-Whitlaws-Computer:~] mikewhitlaw%

hayne 10-01-2002 12:11 AM

one more thing
 
Okay, one more thing and then I'm going to give up.
Please show us the result of:
ls -ld ~/bin

windlaser 10-01-2002 12:15 AM

[Mike-Whitlaws-Computer:~] mikewhitlaw% ls -ld ~/bin
drwxr-xr-x 5 mikewhit staff 170 Sep 30 23:22 /Users/mikewhitlaw/bin
[Mike-Whitlaws-Computer:~] mikewhitlaw%

mervTormel 10-01-2002 02:16 AM

well, raise my rent!

re: ORDERED - it was a suggestion, and speculative. it's difficult to gauge user skill levels.

regardless, it is a quandry. i'm stumped. i'd need access to diagnose.

show us:
Code:

% ls -ld /Users /Users/mikewhitlaw

% id


hayne 10-01-2002 02:53 AM

try to reproduce it
 
Can you reproduce this mysterious behaviour with:
1) a differently named copy of your 'tester' script ? E.g. cp tester foo
2) an executable which is not a shell script ? E.g. copy /bin/ls to ~/bin
3) some other directory than ~/bin ? E.g. make a directory ~/bin2 and try it there.

windlaser 10-01-2002 08:02 AM

Mike-Whitlaws-Computer:~] mikewhitlaw% echo $SHELL
/bin/tcsh
[Mike-Whitlaws-Computer:~] mikewhitlaw% which ls
/bin/ls
[Mike-Whitlaws-Computer:~] mikewhitlaw% mkdir bin2
[Mike-Whitlaws-Computer:~] mikewhitlaw% cp /bin/ls /bin2
[Mike-Whitlaws-Computer:~] mikewhitlaw% echo $PATH
/Users/mikewhitlaw/bin2:~/bin:/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin
[Mike-Whitlaws-Computer:~] mikewhitlaw% which ls
/bin/ls
[Mike-Whitlaws-Computer:~] mikewhitlaw%

---
I changed my default shell to /bin/bash, and I can now execute the script but check out the 'which' call. What the heck is going on?
---


[~]$ echo $SHELL
/bin/bash
[~]$ echo $PATH
~/bin:/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin
[~]$ echo ~/bin
/Users/mikewhitlaw/bin
[~]$ ls ~/bin
tester
[~]$ which tester
no tester in ~/bin /usr/local/bin /bin /sbin /usr/bin /usr/sbin
[~]$ tester
Why can't I be seen?
[~]$ tcsh
[Mike-Whitlaws-Computer:~] mikewhitlaw% which tester
tester: Command not found.
[Mike-Whitlaws-Computer:~] mikewhitlaw% tester
tester: Command not found.
[Mike-Whitlaws-Computer:~] mikewhitlaw% echo $PATH
/Users/mikewhitlaw/bin:/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin
[Mike-Whitlaws-Computer:~] mikewhitlaw% exit
exit
[~]$ tester
Why can't I be seen?
[~]$ which tester
no tester in ~/bin /usr/local/bin /bin /sbin /usr/bin /usr/sbin
[~]$

????

mervTormel 10-01-2002 11:42 AM

Quote:

check out the 'which' call. What the heck is going on?
which is a tcsh builtin, but for bash, which is a C shell script
Code:

$ which which
/usr/bin/which

$ file `which which`
/usr/bin/which: C shell script text

show us, from tcsh
Code:

% sw_vers

ProductName:    Mac OS X
ProductVersion: 10.2.1
BuildVersion:  6D52

% echo $version

tcsh 6.10.00 (Astron) 2000-11-19 (powerpc-apple-darwin) options
 8b,nls,dl,al,sm,rh,color

and, for cripes sake, name your host something reasonable

hayne 10-01-2002 02:57 PM

bin2
 
Quote:

windlaser wrote:
[Mike-Whitlaws-Computer:~] mikewhitlaw% mkdir bin2
[Mike-Whitlaws-Computer:~] mikewhitlaw% cp /bin/ls /bin2
What's going on?
You were supposed to be copy & pasting your results directly from the Terminal.
But the above seems to show that you aren't doing that.
Note the slash in front of bin2 in the 'cp' line. You apparently copied the file to the directory /bin2 which is a subdirectory of /. Yet no such directory exists (usually) and you had created the bin2 directory in your home directory if we believe your prompt.
So I guess we shouldn't believe your prompt. It seems that it does not correctly reflect your current directory. Please preface all further results by showing us the results of 'pwd'.
And for now, please show us just where this bin2 directory is.

mervTormel 10-01-2002 03:06 PM

Quote:

What's going on?
yeah, this has become unsupportable. should we suspect a troll? are we being spoofed? i can no longer look.

windlaser 10-01-2002 09:05 PM

yes, I had to edit out a couple of little mistakes. Looks like I messed up the edit a little. I apologiize. I AM NOT SPOOFING you. I have never seen anything like this before. I mean, why does it work in bash (sort of) and not tcsh. NO ONE has ever seen this before? Is there some kind of privlege setting? What could possibly do this?

Here I'll do what you asked again, no edits (and a few mistakes), I promise:

[Mike-Whitlaws-Computer:~] mikewhitlaw% pwd
/Users/mikewhitlaw
[Mike-Whitlaws-Computer:~] mikewhitlaw% echo $SHELL
/bin/tcsh
[Mike-Whitlaws-Computer:~] mikewhitlaw% echo $PATH
/Users/mikewhitlaw/bin:/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin
[Mike-Whitlaws-Computer:~] mikewhitlaw% setenv PATH (~/bin2:$PATH)
Badly placed ()'s.
[Mike-Whitlaws-Computer:~] mikewhitlaw% setenv PATH "~/bin2:$PATH"
[Mike-Whitlaws-Computer:~] mikewhitlaw% echo $PATH
/Users/mikewhitlaw/bin2:~/bin:/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin
[Mike-Whitlaws-Computer:~] mikewhitlaw% ls bin2
ls
[Mike-Whitlaws-Computer:~] mikewhitlaw% which ls
/bin/ls
[Mike-Whitlaws-Computer:~] mikewhitlaw% ls
Apps Incomplete Music bin
Desktop Library Pictures bin2
Documents LimeWireShared Public java
HelloThere Movies Sites perltest
[Mike-Whitlaws-Computer:~] mikewhitlaw% bash
bash-2.05a$ echo $PATH
~/bin2:~/bin:/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin=
bash-2.05a$ which ls
/bin/ls
bash-2.05a$ ls
Apps Incomplete Music bin
Desktop Library Pictures bin2
Documents LimeWireShared Public java
HelloThere Movies Sites perltest
bash-2.05a$ ls bin
ccrypt tester
bash-2.05a$ tester
Why can't I be seen?
bash-2.05a$ which tester
no tester in ~/bin2 ~/bin /usr/local/bin /bin /sbin /usr/bin /usr/sbin=
bash-2.05a$ cat bin/tester
#!/bin/bash
echo "Why can't I be seen?"

bash-2.05a$ exit
exit
[Mike-Whitlaws-Computer:~] mikewhitlaw% sw_vers
ProductName: Mac OS X
ProductVersion: 10.2.1
BuildVersion: 6D52
[Mike-Whitlaws-Computer:~] mikewhitlaw% echo %version
%version
[Mike-Whitlaws-Computer:~] mikewhitlaw% echo $version
tcsh 6.10.00 (Astron) 2000-11-19 (powerpc-apple-darwin) options 8b,nls,dl,al,sm,rh,color
[Mike-Whitlaws-Computer:~] mikewhitlaw%

---

bottom line. this is messed up, and by the way, this is the installation right out of the box. Oh, and mervTormel, I couldn't agree with you more about the name, how do I rename the host? Forgive my ignorance, but this IS the beginners forum.

mervTormel 10-01-2002 09:28 PM

Quote:

...how do I rename the host? Forgive my ignorance, but this IS the beginners forum.
so it is. and you're doing quite well, actually.

name your rig:

system preferences [ Sharing ] pane:

computer name: [ catbox ]

rendezvous name: [ catbox ]

----------------

re: your dang-puzzling tcsh shell path defiance type thingy, durndest thing i've seen today. would you consider allowing someone to remote connect to diagnose? i'd like to know what the poop is going on.

hayne 10-01-2002 10:32 PM

try using full paths only
 
I can't help but think we are getting confused here by the use of relative paths and the use of ~ in pathnames. Could we please try everything again, using only full path names (starting with a slash)?
E.g. one thing that is strange is that your '/usr/bin/which' command seems to be using the ~ in its output - mine does not.
So please try the following in a tcsh shell and report back on the results. (Don't type in the commands - just copy and paste them into the Terminal all at once, then copy & paste the results back into a Reply here.):

echo $SHELL
setenv PATH "/Users/mikewhitlaw/bin2:/Users/mikewhitlaw/bin:/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin"
echo $PATH
cd
pwd
ls -ld ..
ls -ld .
ls -ld bin
ls -ld bin2
ls -l bin/tester
ls -l bin2/ls
ls bin/tester | wc
ls bin/ls | wc
which which
which tester
which ls
/usr/bin/which tester
/usr/bin/which ls
echo "That's all ..."

windlaser 10-01-2002 10:39 PM

progress!
 
Now this is just figgin wierd: I changed my .login from:

setenv PATH "~/bin:/usr/local/bin:$PATH"

to an explicit

setenv PATH "/users/mikewhitlaw/bin:/usr/local/bin:$PATH"

and it worked! After doing this I noticed the lower case u in /users and thought it curious that this worked. So I changed it to:

setenv PATH "/Users/mikewhitlaw/bin:/usr/local/bin:$PATH"

and that worked too!

It's only when I use:

setenv PATH "~/bin:/usr/local/bin:$PATH"

that it doesn't work.

So now I have two questions:
What's with Users and users being the same?
Why is ~/bin different from /Users/mikewhitlaw/bin?

And I know you'll want proof so:

Last login: Tue Oct 1 22:25:31 on ttyp1
Welcome to Darwin!
[foofy:~] mikewhitlaw% cat .login

setenv PATH "~/bin:/usr/local/bin:$PATH"
[foofy:~] mikewhitlaw% echo $PATH
/Users/mikewhitlaw/bin:/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin
[foofy:~] mikewhitlaw% which tester
tester: Command not found.
[foofy:~] mikewhitlaw%

--- edit .login, close terminal, open terminal ---

Last login: Tue Oct 1 22:33:30 on ttyp1
Welcome to Darwin!
[foofy:~] mikewhitlaw% cat .login

setenv PATH "/users/mikewhitlaw/bin:/usr/local/bin:$PATH"
[foofy:~] mikewhitlaw% echo $PATH
/users/mikewhitlaw/bin:/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin
[foofy:~] mikewhitlaw% which tester
/users/mikewhitlaw/bin/tester
[foofy:~] mikewhitlaw%

--- edit .login, close terminal, open terminal ---

Last login: Tue Oct 1 22:35:13 on ttyp1
Welcome to Darwin!
[foofy:~] mikewhitlaw% cat .login

setenv PATH "/Users/mikewhitlaw/bin:/usr/local/bin:$PATH"
[foofy:~] mikewhitlaw% echo $PATH
/Users/mikewhitlaw/bin:/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin
[foofy:~] mikewhitlaw% which tester
/Users/mikewhitlaw/bin/tester
[foofy:~] mikewhitlaw%


wadaya think?

mervTormel 10-01-2002 10:49 PM

hmm, you dint actually run tester so i'm thinking your testing is incomplete :D

odd that your ~ isn't expanded to your home dir in that respect. but, i'm glad it's over. mostly.

keep diggin'

thanks to hayne for subdividing this nut into its subatomic particles.

pmccann 10-01-2002 10:50 PM

Aah, you guys: it's just that ~ expansion doesn't work to work correctly in setenv calls, so they should always be explicit paths.

The problem is that ~ expansion only works correctly if the ~ is the first character of a word. So even if you have to add a quote mark to the beginning of a setenv call (as per some of the examples above) it'll undermine your expectations.

Funky, but documented in "man tcsh".

Sorry being late to the party on this one: I'm sure you all enjoyed the ride!

Cheers,
Paul

Titanium Man 10-01-2002 10:57 PM

Paul, you're a genius. This has been an entertaining thread.

hayne 10-01-2002 11:26 PM

Two answers
 
Quote:

windlaser wrote:
So now I have two questions:
What's with Users and users being the same?
Why is ~/bin different from /Users/mikewhitlaw/bin?
1) The OS X filesystem (HFS+) is case-preserving but case-insensitive. So it keeps whatever case you use for filenames but it doesn't distinguish Foo from FOO from foo. (or Users from users).
2) As pointed out above by pmccann, the shell does the conversion from ~ to the full path only in certain cases. Here's the relevant extract from 'man tcsh':
Quote:

The character `~' at the beginning of a filename refers to
home directories. Standing alone, i.e., `~', it expands
to the invoker's home directory as reflected in the value
of the home shell variable. When followed by a name con-
sisting of letters, digits and `-' characters the shell
searches for a user with that name and substitutes their
home directory; thus `~ken' might expand to `/usr/ken' and
`~ken/chmach' to `/usr/ken/chmach'. If the character `~'
is followed by a character other than a letter or `/' or
appears elsewhere than at the beginning of a word, it is
left undisturbed. A command like `setenv MANPATH
/usr/man:/usr/local/man:~/lib/man' does not, therefore, do
home directory substitution as one might hope.

windlaser 10-01-2002 11:36 PM

Thanks to all
 
This has been a big help. My faith has been restored...

stetner 10-02-2002 08:40 AM

And I have been given another reason to avoid 'csh' type shells like the plague!

sh or ksh for me.

pmccann 10-02-2002 09:45 PM

Hey Doug,

come to where the flavour is: zsh country. It's been nothing short of smile-inducing in the time I've been using it (and should prove eminently comfortable for a ksh'er).

You know you want to.

Cheers,
Paul

ps Jaguar includes zsh 4.04, which is not too old. (4.05 seems to have been released in Aug 2002, a bit late for 10.2)


All times are GMT -5. The time now is 10:33 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.