Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Linux version
Linux ldalxxx 2.6.18-238.12.1.0.1.el5 #1 SMP Tue May 31 14:51:07 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux
We have a lot of AIX/Solaris Unix boxes that use a lot of Korn shell environment setup and scripts.
The problem comes on this new Linux box with how the Path statement gets used and remembered.
On Unix, the path gets searched every time you execute something.
On Linux, it remembers where it found it last time and will reuse that, even if a newer version of the command is now earlier in the path.
hash -r will clear that, but I need to turn this feature off.
set +h Should do this.
Set +h works correctly if I am in Bash shell, but not in Korn Shell.
I really need a way to turn this "feature" off in our Korn shell Linux environments.
( I have also tried switch to Bash shell, turn it off, and switch to Korn to see if it was then off. It is back on in Korn shell).
Please let me know if there is any way to turn this off under a Korn shell.
Thanks
In Korn shell, set +h is "accepted" as a command, but it does not turn off directory "hashing".
These sessions need to remain in Korn shell, and manually resetting the hash with hash -r is not feasable. I need to turn it off in the profile and leave it off so that it will honor the path variable for every command.
Again, set +h works as expected IF I switch to Bash. Fails if I am in Korn.
Sample session log. . .
$ echo $SHELL
/bin/ksh
$ pwd
/export/home/cfsh_mgr
$ which test.ksh
~/testdir/test.ksh
$ echo $PATH
/export/home/cfsh_mgr/testdir:/export/home/cfsh_mgr:/usr/kerberos/bin:/usr/bin:/bin:/sbin:/usr/sbin:/fisc/sysman/bin:/fisc/uts/bin
$
$ cat test.ksh
echo IN THE HOME DIRECTORY!!!!!!!
$ cat ~/testdir/test.ksh
echo IN THE SUB DIRECTORY!!!!!!!
$ # it finds the correct test.ksh in the testdir. . .
$ test.ksh
IN THE SUB DIRECTORY!!!!!!!
$ rm ~/testdir/test.ksh
$
$ # Which show the only remaining version.
$ which test.ksh
~/test.ksh
$ # whence shows the now missing cached location.
$ whence test.ksh
/export/home/cfsh_mgr/testdir/test.ksh
$
$ # Notice, it still tries to go to the hashed sub dir version.
$ test.ksh
-ksh: test.ksh: not found [No such file or directory]
$
$ # it accepts the set +h but ignores it. Yes, I have tried this
$ # at the TOP of my session before any location lookups as well.
$ # if I were in Bash shell, the set +h works fine.
$ set +h
$ test.ksh
-ksh: test.ksh: not found [No such file or directory]
$
$ # hash -r works in Bash AND Korn to clear out the saved locations.
$ hash -r
$ test.ksh
IN THE HOME DIRECTORY!!!!!!!
$
Last edited by dwf; 11-08-2011 at 01:29 PM.
Reason: add ending comments.
I think +h stops the shell automatically adding tracked aliases but doesn't clear the tracked-alias table. Try doing hash -r when you do the set +h, or just do set +h right at the start....
Also:
Quote:
I have also tried switch to Bash shell, turn it off, and switch to Korn to see if it was then off. It is back on in Korn shell
bash and ksh don't talk to each other unless you put a fair amount of effort into setting up a custom environment that works that way. If you have one of those, debugging the communications failure is a separate problem.
jthill,
Thank you so much for checking your box. Now at least I know that it is specific to either my Linux or KSH version and not generic to all Linux.
My output below, and If anyone would like to check there own version, I have just the command pulled out at the very bottom so you can cut and just paste the whole set of commands to try it on your box.
My output
$ echo $KSH_VERSION
Version AJM 93t+ 2010-02-02
$ set +h
$ mkdir ~/sandbox
$ mkdir ~/bin
$ PATH=~/sandbox:~/bin:$PATH
$ echo PATH is $PATH
PATH is /export/home/cfsh_mgr/sandbox:/export/home/cfsh_mgr/bin:/usr/kerberos/bin:/usr/bin:/bin:/sbin:/usr/sbin:/fisc/sysman/bin:/fisc/uts/bin:.
$ echo echo bin > ~/bin/foo
$ chmod +x ~/bin/foo
$ echo You should see bin displayed
You should see bin displayed
$ foo
bin
$ echo echo sandbox > sandbox/foo
$ chmod +x sandbox/foo
$ echo You should see sandbox displayed
You should see sandbox displayed
$ foo
bin
$ chmod -x sandbox/foo
$ echo You should see bin displayed
You should see bin displayed
$ foo
bin
$ rm ~/sandbox/foo
$ rm ~/bin/foo
$ rmdir ~/sandbox
$ rmdir ~/bin
$ echo You should see that foo is not found
You should see that foo is not found
$ foo
-ksh: foo: not found [No such file or directory]
Here are just the commands you can paste to try
echo $KSH_VERSION
set +h
mkdir ~/sandbox
mkdir ~/bin
PATH=~/sandbox:~/bin:$PATH
echo PATH is $PATH
echo echo bin > ~/bin/foo
chmod +x ~/bin/foo
echo You should see bin displayed
foo
echo echo sandbox > sandbox/foo
chmod +x sandbox/foo
echo You should see sandbox displayed
foo
chmod -x sandbox/foo
echo You should see bin displayed
foo
rm ~/sandbox/foo
rm ~/bin/foo
rmdir ~/sandbox
rmdir ~/bin
echo You should see that foo is not found
foo
So thanks tjhill, now at least I have a place to start looking. I was beginning to think I needed a different command in KSH or it just would not function in KSH or something like that.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.