What is the shell VIM uses for ":!<command>" ?

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

What is the shell VIM uses for ":!<command>" ?

Bill Yoder

I'm trying to use :!command to execute commands without dropping
into :sh, but they seem to behave differently.

For instance, when I do an 'alias' from :sh, it properly shows me the
aliases set up in .kshrc (using ksh). If I do :!alias, I do not get
any of the aliases I set up in my .kshrc.

Does anyone know how to rectify this, or at least explain it?

Thanks very much in advance!
Bill Yoder
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: What is the shell VIM uses for ":!<command>" ?

bill lam

On Mon, 09 Feb 2009, WiggyWare wrote:

>
> I'm trying to use :!command to execute commands without dropping
> into :sh, but they seem to behave differently.
>
> For instance, when I do an 'alias' from :sh, it properly shows me the
> aliases set up in .kshrc (using ksh). If I do :!alias, I do not get
> any of the aliases I set up in my .kshrc.
>
> Does anyone know how to rectify this, or at least explain it?
>

For bash, alias is a builtin command of shell, not as an external
command. Try verify by
type alias
where alias

--
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
唐詩282 白居易  後宮詞
    淚濕羅巾夢不成  夜深前殿按歌聲  紅顏未老恩先斷  斜倚薰籠坐到明

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: What is the shell VIM uses for ":!<command>" ?

bill lam

On Mon, 09 Feb 2009, bill lam wrote:

> On Mon, 09 Feb 2009, WiggyWare wrote:
> >
> > I'm trying to use :!command to execute commands without dropping
> > into :sh, but they seem to behave differently.
> >
> > For instance, when I do an 'alias' from :sh, it properly shows me the
> > aliases set up in .kshrc (using ksh). If I do :!alias, I do not get
> > any of the aliases I set up in my .kshrc.
> >
> > Does anyone know how to rectify this, or at least explain it?
> >
>
> For bash, alias is a builtin command of shell, not as an external
> command. Try verify by
> type alias
> where alias

sorry, typo:
type alias
which alias
whereis alias

--
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
唐詩232 孟浩然  春曉
    春眠不覺曉  處處聞啼鳥  夜來風雨聲  花落知多少

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: What is the shell VIM uses for ":!<command>" ?

Jason Foreman
In reply to this post by Bill Yoder

On Mon, Feb 9, 2009 at 7:45 AM, WiggyWare <[hidden email]> wrote:
>
> I'm trying to use :!command to execute commands without dropping
> into :sh, but they seem to behave differently.
>
> For instance, when I do an 'alias' from :sh, it properly shows me the
> aliases set up in .kshrc (using ksh). If I do :!alias, I do not get
> any of the aliases I set up in my .kshrc.
>
> Does anyone know how to rectify this, or at least explain it?

Vim uses the 'shell' variable, along with a handful of others which
control options.

:set shell?
:h 'shell'


Jason

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: What is the shell VIM uses for ":!<command>" ?

Teemu Likonen
In reply to this post by bill lam

On 2009-02-09 22:28 (+0800), bill lam wrote:

> For bash, alias is a builtin command of shell, not as an external
> command.

Being a shell built-in command is not the issue. For example, "cd" is
also a built-in and it works in non-interactive shells:

    $ bash -c "cd / && ls"

(Vim's :! command runs a non-interactive shell.)

But aliases don't work there because they are expanded only in
interactive shells.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: What is the shell VIM uses for ":!<command>" ?

Bill Yoder



On Feb 9, 9:58 am, Teemu Likonen <[hidden email]> wrote:

> On 2009-02-09 22:28 (+0800), bill lam wrote:
>
> > For bash, alias is a builtin command of shell, not as an external
> > command.
>
> Being a shell built-in command is not the issue. For example, "cd" is
> also a built-in and it works in non-interactive shells:
>
>     $ bash -c "cd / && ls"
>
> (Vim's :! command runs a non-interactive shell.)
>
> But aliases don't work there because they are expanded only in
> interactive shells.

Ahh, thank you. I knew I had the shell set properly, but I didn't
realize that about alias.

Thanks again!
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: What is the shell VIM uses for ":!<command>" ?

Ted Pavlic
In reply to this post by Teemu Likonen

> But aliases don't work there because they are expanded only in
> interactive shells.

Use

        :set shcf=-cl

to get

        :!alias

to give you the expected result.

--Ted


--
Ted Pavlic <[hidden email]>

   Please visit my ALS association page:
         http://web.alsa.org/goto/tedpavlic
   My family appreciates your support in the fight to defeat ALS.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: What is the shell VIM uses for ":!<command>" ?

Ted Pavlic
In reply to this post by Bill Yoder

> Ahh, thank you. I knew I had the shell set properly, but I didn't
> realize that about alias.

It's not just shell, but shellcmdflag too

        :help shcf

--Ted

--
Ted Pavlic <[hidden email]>

   Please visit my ALS association page:
         http://web.alsa.org/goto/tedpavlic
   My family appreciates your support in the fight to defeat ALS.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: What is the shell VIM uses for ":!<command>" ?

Tony Mechelynck
In reply to this post by Bill Yoder

On 09/02/09 14:45, WiggyWare wrote:

> I'm trying to use :!command to execute commands without dropping
> into :sh, but they seem to behave differently.
>
> For instance, when I do an 'alias' from :sh, it properly shows me the
> aliases set up in .kshrc (using ksh). If I do :!alias, I do not get
> any of the aliases I set up in my .kshrc.
>
> Does anyone know how to rectify this, or at least explain it?
>
> Thanks very much in advance!
> Bill Yoder

IIUC, Vim runs your usual shell, but as a non-interactive shell. This
means that bash won't source .bashrc, ksh won't source .kshrc, etc.

In Console mode, or when started in GUI mode from a shell, this should
not be a problem, since in that case Vim runs in an environment set up
by an earlier (interactive) shell, and passes that to every child process.

When started from a desktop icon, or from the "Execute" menu on the
taskbar, OTOH, there is no previous shell, and there are no preset
variables to pass.

To define your aliases even in a non-interactive shell, define them in
~/.profile or (system-wide) /etc/profile rather than in .bashrc or
.kshrc (or the equivalent *rc files for csh, zsh, etc.).

If sh (when interactive) gets you the same aliases as ksh, it could mean
that your sh is actually softlinked to ksh, the way on my system is it
softlinked to /bin/bash.


Best regards,
Tony.
--
God made the world in six days, and was arrested on the seventh.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: What is the shell VIM uses for ":!<command>" ?

Gary Johnson-4

On 2009-02-10, Tony Mechelynck <[hidden email]> wrote:

> On 09/02/09 14:45, WiggyWare wrote:
> > I'm trying to use :!command to execute commands without dropping
> > into :sh, but they seem to behave differently.
> >
> > For instance, when I do an 'alias' from :sh, it properly shows me the
> > aliases set up in .kshrc (using ksh). If I do :!alias, I do not get
> > any of the aliases I set up in my .kshrc.
> >
> > Does anyone know how to rectify this, or at least explain it?
> >
> > Thanks very much in advance!
> > Bill Yoder
>
> IIUC, Vim runs your usual shell, but as a non-interactive shell. This
> means that bash won't source .bashrc, ksh won't source .kshrc, etc.
>
> In Console mode, or when started in GUI mode from a shell, this should
> not be a problem, since in that case Vim runs in an environment set up
> by an earlier (interactive) shell, and passes that to every child process.

It's still a problem because unlike environment variables, aliases
are not exported to child processes.  (I think there are some
exceptions to this, but they don't apply in this case anyway.)

> To define your aliases even in a non-interactive shell, define them in
> ~/.profile or (system-wide) /etc/profile rather than in .bashrc or
> .kshrc (or the equivalent *rc files for csh, zsh, etc.).

That doesn't work, at least not for ksh or bash.

Regards,
Gary



--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: What is the shell VIM uses for ":!<command>" ?

Matt Wozniski-2

On Tue, Feb 10, 2009 at 5:58 PM, Gary Johnson wrote:

>
> On 2009-02-10, Tony Mechelynck wrote:
>>
>> On 09/02/09 14:45, WiggyWare wrote:
>> >
>> > For instance, when I do an 'alias' from :sh, it properly shows me the
>> > aliases set up in .kshrc (using ksh). If I do :!alias, I do not get
>> > any of the aliases I set up in my .kshrc.
>>
>> IIUC, Vim runs your usual shell, but as a non-interactive shell. This
>> means that bash won't source .bashrc, ksh won't source .kshrc, etc.

Bash also won't source .bash_profile or .profile.  See INVOCATION in
bash(1) - you'd need to do, say,

export BASH_ENV="$HOME/.bashrc"

to make that work, and that would probably be a bad idea.

>> In Console mode, or when started in GUI mode from a shell, this should
>> not be a problem, since in that case Vim runs in an environment set up
>> by an earlier (interactive) shell, and passes that to every child process.
>
> It's still a problem because unlike environment variables, aliases
> are not exported to child processes.  (I think there are some
> exceptions to this, but they don't apply in this case anyway.)

There are no exceptions to this.  Aliases are held within a shell,
there's no way to "pass" an alias to another process.

>> To define your aliases even in a non-interactive shell, define them in
>> ~/.profile or (system-wide) /etc/profile rather than in .bashrc or
>> .kshrc (or the equivalent *rc files for csh, zsh, etc.).
>
> That doesn't work, at least not for ksh or bash.

Nor should it.  Aliases are a purely interactive feature, they don't
even make sense in non-interactive shells.  You can force vim to make
shells interactive by tweaking shellcmdflag, or you can force bash to
use aliases in non-interactive shells with

bash -O expand_aliases alias

or

shopt -s expand_aliases

But anyway, the three general solutions are 1) create scripts instead
of aliases, since if you want to use them from within another program
aliases aren't even the right tool for the job, 2) ask vim to start
interactive shells using 'shellcmdflag', or 3) ask bash to use aliases
in non-interactive shells, probably using $BASH_ENV.

But, note that 3 has the potential to break distributed scripts, if
you define an alias that they expect to use as a function instead...

~Matt

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: What is the shell VIM uses for ":!<command>" ?

Gary Johnson-4

On 2009-02-10, Matt Wozniski <[hidden email]> wrote:
> On Tue, Feb 10, 2009 at 5:58 PM, Gary Johnson wrote:
> >
> > On 2009-02-10, Tony Mechelynck wrote:

> >> In Console mode, or when started in GUI mode from a shell, this should
> >> not be a problem, since in that case Vim runs in an environment set up
> >> by an earlier (interactive) shell, and passes that to every child process.
> >
> > It's still a problem because unlike environment variables, aliases
> > are not exported to child processes.  (I think there are some
> > exceptions to this, but they don't apply in this case anyway.)
>
> There are no exceptions to this.  Aliases are held within a shell,
> there's no way to "pass" an alias to another process.

Some shells have an alias command that takes a -x option which is
supposed to export the specified alias.  For example,
http://www.mkssoftware.com/docs/man1/alias.1.asp says,

    -x

        marks each alias name on the command line for export. If you
        specify -x without any names, alias displays all exported
        aliases. Only exported aliases are passed to a shell that
        runs a shell script (that is, script.ksh).

I think that means that if you are running an instance of that shell
and you launch a shell script from it, that shell script can inherit
exported aliases.  However, if from that first shell you launched
some other program, such as vim, and from that program you launched
a shell, that second shell would not inherit any aliases.

I don't have access to a shell that it supposed to do that, though,
so I can't test it.  The ksh man page on the Linux system running
nearby says,

    The -x option sets (+x clears) the export attribute of an alias,
    or, if no names are given, lists the aliases with the export
    attribute (exporting an alias has no affect[sic]).

Regards,
Gary



--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: What is the shell VIM uses for ":!<command>" ?

Anton-3

2009/2/11, Gary Johnson <[hidden email]>:

>
> On 2009-02-10, Matt Wozniski <[hidden email]> wrote:
>> On Tue, Feb 10, 2009 at 5:58 PM, Gary Johnson wrote:
>> >
>> > On 2009-02-10, Tony Mechelynck wrote:
>
>> >> In Console mode, or when started in GUI mode from a shell, this should
>> >> not be a problem, since in that case Vim runs in an environment set up
>> >> by an earlier (interactive) shell, and passes that to every child
>> >> process.
>> >
>> > It's still a problem because unlike environment variables, aliases
>> > are not exported to child processes.  (I think there are some
>> > exceptions to this, but they don't apply in this case anyway.)
>>
>> There are no exceptions to this.  Aliases are held within a shell,
>> there's no way to "pass" an alias to another process.
>
> Some shells have an alias command that takes a -x option which is
> supposed to export the specified alias.  For example,
> http://www.mkssoftware.com/docs/man1/alias.1.asp says,
>
>     -x
>
>         marks each alias name on the command line for export. If you
>         specify -x without any names, alias displays all exported
>         aliases. Only exported aliases are passed to a shell that
>         runs a shell script (that is, script.ksh).
>
> I think that means that if you are running an instance of that shell
> and you launch a shell script from it, that shell script can inherit
> exported aliases.  However, if from that first shell you launched
> some other program, such as vim, and from that program you launched
> a shell, that second shell would not inherit any aliases.
>
> I don't have access to a shell that it supposed to do that, though,
> so I can't test it.  The ksh man page on the Linux system running
> nearby says,
>
>     The -x option sets (+x clears) the export attribute of an alias,
>     or, if no names are given, lists the aliases with the export
>     attribute (exporting an alias has no affect[sic]).
>
> Regards,
> Gary
>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: What is the shell VIM uses for ":!<command>" ?

Tony Mechelynck
In reply to this post by Gary Johnson-4

On 11/02/09 04:00, Gary Johnson wrote:

> On 2009-02-10, Matt Wozniski<[hidden email]>  wrote:
>> On Tue, Feb 10, 2009 at 5:58 PM, Gary Johnson wrote:
>>> On 2009-02-10, Tony Mechelynck wrote:
>
>>>> In Console mode, or when started in GUI mode from a shell, this should
>>>> not be a problem, since in that case Vim runs in an environment set up
>>>> by an earlier (interactive) shell, and passes that to every child process.
>>> It's still a problem because unlike environment variables, aliases
>>> are not exported to child processes.  (I think there are some
>>> exceptions to this, but they don't apply in this case anyway.)
>> There are no exceptions to this.  Aliases are held within a shell,
>> there's no way to "pass" an alias to another process.
>
> Some shells have an alias command that takes a -x option which is
> supposed to export the specified alias.  For example,
> http://www.mkssoftware.com/docs/man1/alias.1.asp says,
>
>      -x
>
>          marks each alias name on the command line for export. If you
>          specify -x without any names, alias displays all exported
>          aliases. Only exported aliases are passed to a shell that
>          runs a shell script (that is, script.ksh).
>
> I think that means that if you are running an instance of that shell
> and you launch a shell script from it, that shell script can inherit
> exported aliases.  However, if from that first shell you launched
> some other program, such as vim, and from that program you launched
> a shell, that second shell would not inherit any aliases.
>
> I don't have access to a shell that it supposed to do that, though,
> so I can't test it.  The ksh man page on the Linux system running
> nearby says,
>
>      The -x option sets (+x clears) the export attribute of an alias,
>      or, if no names are given, lists the aliases with the export
>      attribute (exporting an alias has no affect[sic]).
>
> Regards,
> Gary

In the version of bash installed here (GNU bash 3.2.39),

        alias

with no arguments at all outputs all aliases in the form

alias name1='value1'
alias name2='value2'
alias name3='value3'

etc. on standard output, which is acceptable as input. Otherwise, "alias
name1 name2 name3" does the same for just the names given, "alias
name=value" (which requires an equal sign) sets them.

ksh (AT&T Research 93t 2008-11-04) behaves the same with "alias -p" (but
no additional arguments); its manpage says explicitly that "the obsolete
-x option [to the alias command] has no effect".

Best regards,
Tony.
--
Don't suspect your friends -- turn them in!
                -- "Brazil"

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---