bug? vim for freebsd doesn't know the cmd that set after login.

5 views
Skip to first unread message

anhnmncb

unread,
Nov 24, 2008, 6:39:25 PM11/24/08
to vim...@googlegroups.com
Sometimes I add a path to $PATH after login (i.e. after source the
.cshrc), and I'm sure I can run that path's command in console, but when
I run vim and use :!cmd, then vim will prompt the command not found.
I have to add that path to $PATH in .cshrc.

OS is freebsd 7-stable.
Shell is tcsh.
--
Regards,

anhnmncb
gpg key: 44A31344

John Beckett

unread,
Nov 24, 2008, 7:55:05 PM11/24/08
to vim...@googlegroups.com
anhnmncb wrote:
> Sometimes I add a path to $PATH after login (i.e. after
> source the .cshrc), and I'm sure I can run that path's
> command in console, but when I run vim and use :!cmd, then
> vim will prompt the command not found.
> I have to add that path to $PATH in .cshrc.

In Vim, does the following show the correct PATH?

:echo $PATH
:put =$PATH

The second command will insert it into the current buffer for inspection.

Of course Vim just asks the operating system to handle '!cmd' so the only issue is
whether the PATH is inherited by the process started by Vim (I would say "yes").
First point is to decide if Vim's process has that info.

John

Ben Schmidt

unread,
Nov 24, 2008, 8:00:18 PM11/24/08
to vim...@googlegroups.com
>> Sometimes I add a path to $PATH after login (i.e. after
>> source the .cshrc),

How do you do that? Did you export it? If you just do

set PATH=whatever

in a shell, it will only apply in the shell, not to processes started by
the shell, you need to do

setenv PATH=whatever

or perhaps at an appropriate point set the environment variable to equal
the shell variable with something like

setenv PATH=$PATH

Ben.

anhnmncb

unread,
Nov 24, 2008, 8:25:08 PM11/24/08
to vim...@googlegroups.com
"John Beckett" <johnb....@gmail.com> writes:

> anhnmncb wrote:
>> Sometimes I add a path to $PATH after login (i.e. after
>> source the .cshrc), and I'm sure I can run that path's
>> command in console, but when I run vim and use :!cmd, then
>> vim will prompt the command not found.
>> I have to add that path to $PATH in .cshrc.
>
> In Vim, does the following show the correct PATH?
>
> :echo $PATH
> :put =$PATH
>
> The second command will insert it into the current buffer for inspection.

In my .cshrc:

set path = (/sbin /bin /usr/sbin /usr/bin /usr/games /usr/local/sbin
/usr/local/bin $HOME/bin)

---- Then I start a screen session in urxvt and set the path:

$ screen

$ echo $PATH
/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/home/anhnmncb/bin

$ setenv PATH /home/anhnmncb/apps/context/tex/texmf-freebsd/bin:$PATH

$ echo $PATH
/home/anhnmncb/apps/context/tex/texmf-freebsd/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/home/anhnmncb/bin

$ context foo.tex <= runs ok.

$ vim

----- now I do it in vim:
:echo $PATH
/home/anhnmncb/apps/context/tex/texmf-freebsd/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/home/anhnmncb/bin

:!context %
context: Command not found.

:version
VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Nov 9 2008 09:58:06)
Included patches: 1-6, 8-26, 28-29
Compiled by ro...@fbsd.hasee.cpu
Big version with GTK2 GUI. Features included (+) or not (-):
+arabic +autocmd +balloon_eval +browse ++builtin_terms +byte_offset +cindent +clientserver +clipboard
+cmdline_compl +cmdline_hist +cmdline_info +comments +cryptv +cscope +cursorshape +dialog_con_gui +diff
+digraphs +dnd -ebcdic +emacs_tags +eval +ex_extra +extra_search +farsi +file_in_path +find_in_path +float
+folding -footer +fork() -gettext -hangul_input +iconv +insert_expand +jumplist +keymap +langmap +libcall
+linebreak +lispindent +listcmds +localmap +menu +mksession +modify_fname +mouse +mouseshape +mouse_dec
-mouse_gpm -mouse_jsbterm +mouse_netterm +mouse_sysmouse +mouse_xterm +multi_byte +multi_lang -mzscheme
+netbeans_intg -osfiletype +path_extra +perl +postscript +printer -profile +python +quickfix +reltime +rightleft
-ruby +scrollbind +signs +smartindent -sniff +statusline -sun_workshop +syntax +tag_binary +tag_old_static
-tag_any_white -tcl +terminfo +termresponse +textobjects +title +toolbar +user_commands +vertsplit +virtualedit
+visual +visualextra +viminfo +vreplace +wildignore +wildmenu +windows +writebackup +X11 -xfontset +xim
+xsmp_interact +xterm_clipboard -xterm_save
system vimrc file: "$VIM/vimrc"
user vimrc file: "$HOME/.vimrc"
user exrc file: "$HOME/.exrc"
system gvimrc file: "$VIM/gvimrc"
user gvimrc file: "$HOME/.gvimrc"
system menu file: "$VIMRUNTIME/menu.vim"
fall-back for $VIM: "/usr/local/share/vim"
Compilation: cc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK -D_THREAD_SAFE -I/usr/local/include/gtk-2.0 -I/usr
/local/lib/gtk-2.0/include -I/usr/local/include/atk-1.0 -I/usr/local/include/cairo -I/usr/local/include/pango-1.0
-I/usr/local/include -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/usr/local/include/freety
pe2 -I/usr/local/include/pixman-1 -I/usr/local/include -O2 -fno-strict-aliasing -pipe -march=pentium-m -march=pe
ntium-m -DAPPLLIB_EXP="/usr/local/lib/perl5/5.8.8/BSDPAN" -DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -I/usr/local
/include -I/usr/local/lib/perl5/5.8.8/mach/CORE -I/usr/local/include/python2.5 -D_THREAD_SAFE
Linking: cc -L/usr/local/lib -Wl,-R/usr/local/lib/perl5/5.8.8/mach/CORE -L/usr/local/lib -o vim -pthread -L/u
sr/local/lib -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lpangocairo-1.0 -lXext -lXrender -lXinerama
-lXi -lXrandr -lXcursor -lXcomposite -lXdamage -lcairo -lpangoft2-1.0 -lpango-1.0 -lfreetype -lz -lfontconfig -lX
fixes -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -lXt -pthread -ltermlib -Wl,-R/usr/local/lib/perl5/5.8.8/mach/CORE
-Wl,-E -L/usr/local/lib /usr/local/lib/perl5/5.8.8/mach/auto/DynaLoader/DynaLoader.a -L/usr/local/lib/perl5/5.8.8
/mach/CORE -lperl -lutil -L/usr/local/lib/python2.5/config -lpython2.5
-lutil -lm -Wl,--export-dynamic

--------- End

My FreeBSD version:
uname -a
FreeBSD fbsd.hasee.cpu 7.1-PRERELEASE FreeBSD 7.1-PRERELEASE #0: Sun Oct 12 02:07:02 CST 2008 ro...@fbsd.hasee.cpu:/usr/obj/usr/src/sys/HASEE i386

>
> Of course Vim just asks the operating system to handle '!cmd' so the only issue is
> whether the PATH is inherited by the process started by Vim (I would say "yes").
> First point is to decide if Vim's process has that info.
>
> John
>
>
> >
>
>

Ben Schmidt

unread,
Nov 24, 2008, 8:36:17 PM11/24/08
to vim...@googlegroups.com

I think it's because the :! command in Vim starts a new shell. Because
your .cshrc sets path, when this new shell is started, the shell reads
its .cshrc and clobbers the PATH that it was passed in the environment.

You should probably solve this by putting your alteration to path in
~/.login (or ~/.csh.login?) instead of ~/.cshrc so it only happens for a
login shell, not every shell, since you actually want non-login shells
to inherit the environment from their parent process. Even better would
be to have it as an alteration to the system default path in ~/.login
(i.e. prepend or append to the existing $PATH rather than setting it
outright).

Cheers,

Ben.

anhnmncb

unread,
Nov 24, 2008, 8:52:55 PM11/24/08
to vim...@googlegroups.com
I notice that when on linux, it hasn't such problem in bash, maybe it's
a problem relative to tcsh? But I'm sorry I can't test it at this time
:(

I just want an env implemented in a particular shell in one particular
screen window, so the ~/.login isn't what I need.

>
> Cheers,
>
> Ben.

Ben Schmidt

unread,
Nov 24, 2008, 9:04:12 PM11/24/08
to vim...@googlegroups.com
>> You should probably solve this by putting your alteration to path in
>> ~/.login (or ~/.csh.login?) instead of ~/.cshrc so it only happens for a
>> login shell, not every shell, since you actually want non-login shells
>> to inherit the environment from their parent process. Even better would
>> be to have it as an alteration to the system default path in ~/.login
>> (i.e. prepend or append to the existing $PATH rather than setting it
>> outright).
>
> I notice that when on linux, it hasn't such problem in bash, maybe it's
> a problem relative to tcsh? But I'm sorry I can't test it at this time
> :(

You would have the same problem in bash if you did the same thing in
your .bashrc.

> I just want an env implemented in a particular shell in one particular
> screen window, so the ~/.login isn't what I need.

Yes, I understand. I'm not suggesting you put your context path in
.login, I'm suggesting you move

> set path = (/sbin /bin /usr/sbin /usr/bin /usr/games /usr/local/sbin
> /usr/local/bin $HOME/bin)

from .cshrc to .login.

The problem is that when Vim does :! it starts tcsh, which reads .cshrc,
which runs that line above which sets the path so it loses the path the
Vim had that included the context path.

Just removing that line above from your .cshrc should fix it, but
obviously that's not what you want. Nor do you want to change that line
to something that includes $PATH on its right hand side, because doing
that would mean the path would get longer and longer every subshell that
got started (and many do!). The best thing is to put it in .login.

Ben.

anhnmncb

unread,
Nov 24, 2008, 9:55:16 PM11/24/08
to vim...@googlegroups.com
Hmm, it solves the problem, I think I tested in bash without the .bashrc
that contents path setting line, so no such problem.

Many thanks for patient and detailed explanation :)

Tony Mechelynck

unread,
Nov 26, 2008, 6:54:04 AM11/26/08
to vim...@googlegroups.com
On 25/11/08 02:52, anhnmncb wrote:
[...]

> I notice that when on linux, it hasn't such problem in bash, maybe it's
> a problem relative to tcsh? But I'm sorry I can't test it at this time
> :(
>
> I just want an env implemented in a particular shell in one particular
> screen window, so the ~/.login isn't what I need.
[...]

I don't know about [t]csh, but bash determines which scripts to source
at startup according to whether or not it's a login shell and whether or
not it's an interactive shell. When Vim starts a bash shell, to handle a
:! command, it is (in the general case) neither a login shell nor an
interactive shell, and it inherits the environment from Vim, though some
settings may be modified before the :!command is run.


Best regards,
Tony.
--
Please try to limit the amount of "this room doesn't have any bazingas"
until you are told that those rooms are "punched out". Once punched
out, we have a right to complain about atrocities, missing bazingas,
and such.
-- N. Meyrowitz

anhnmncb

unread,
Nov 26, 2008, 9:53:41 AM11/26/08
to vim...@googlegroups.com
On 2008-11-26, Tony Mechelynck wrote:
>
> On 25/11/08 02:52, anhnmncb wrote:
> [...]
>> I notice that when on linux, it hasn't such problem in bash, maybe it's
>> a problem relative to tcsh? But I'm sorry I can't test it at this time
>> :(
>>
>> I just want an env implemented in a particular shell in one particular
>> screen window, so the ~/.login isn't what I need.
> [...]
>
> I don't know about [t]csh, but bash determines which scripts to source
> at startup according to whether or not it's a login shell and whether or
> not it's an interactive shell. When Vim starts a bash shell, to handle a
>:! command, it is (in the general case) neither a login shell nor an
> interactive shell, and it inherits the environment from Vim, though some
> settings may be modified before the :!command is run.

Problem has resolved :) I think tcsh reads .cshrc no matter if is login shell
or interactive shell.

>
>
> Best regards,
> Tony.

Reply all
Reply to author
Forward
0 new messages