* executing bash function with shell-command
@ 2016-02-22 19:58 mvar
2016-02-23 0:27 ` Emanuel Berg
0 siblings, 1 reply; 5+ messages in thread
From: mvar @ 2016-02-22 19:58 UTC (permalink / raw
To: help-gnu-emacs
Hello,
Apologies if this has been asked before, i couldn't find something relevant
in the archives!
I've been trying to setup a lisp function in emacs (24.5.1) that executes
an external bash function defined in my .bashrc file (or even .emacs_bash).
If i open the shell directly from within emacs and type the function in there
it works, but if i call it with "shell-command" i get a "command not found" error.
A workaround is to run shell-command with "source ~/.emacs-bash && function_name".
Am i doing something horribly wrong?
another question, is it viable to create some function/script in Lisp
that for example will ssh to a remote machine, execute some pre-defined
commands and log-off ? The only relevant info i've found so far is for
remote editing with tramp.
thanks,
Michael
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: executing bash function with shell-command
2016-02-22 19:58 executing bash function with shell-command mvar
@ 2016-02-23 0:27 ` Emanuel Berg
2016-02-23 0:34 ` Emanuel Berg
0 siblings, 1 reply; 5+ messages in thread
From: Emanuel Berg @ 2016-02-23 0:27 UTC (permalink / raw
To: help-gnu-emacs
mvar <mvar.40k@gmail.com> writes:
> I've been trying to setup a lisp function in emacs
> (24.5.1) that executes an external bash function
> defined in my .bashrc file (or even .emacs_bash).
> If i open the shell directly from within emacs and
> type the function in there it works, but if i call
> it with "shell-command" i get a "command not
> found" error.
It is because when you open bash from Emacs bash is
the interactive shell. When you open Emacs from bash
Emacs talks to a non-interactive bash where BASH_ENV
is the only thing that is sourced. (Or so I've heard -
I don't use bash myself - I use zsh, where you solve
this by putting shared stuff in .zshenv)
So try putting the shared file path in BASH_ENV, or
you can even try:
BASH_ENV=~/.bashrc emacs
The the distinction interactive/non-interactive gets
foggy but I suppose your computer won't blow up.
> A workaround is to run shell-command with "source
> ~/.emacs-bash && function_name".
Indeed, the material is not read is the problem.
> another question, is it viable to create some
> function/script in Lisp that for example will ssh to
> a remote machine, execute some pre-defined commands
> and log-off ? The only relevant info i've found so
> far is for remote editing with tramp.
Yes, you can do that.
--
underground experts united
http://user.it.uu.se/~embe8573
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: executing bash function with shell-command
2016-02-23 0:27 ` Emanuel Berg
@ 2016-02-23 0:34 ` Emanuel Berg
0 siblings, 0 replies; 5+ messages in thread
From: Emanuel Berg @ 2016-02-23 0:34 UTC (permalink / raw
To: help-gnu-emacs
Emanuel Berg <embe8573@student.uu.se> writes:
> It is because when you open bash from Emacs bash is
> the interactive shell. When you open Emacs from bash
> Emacs talks to a non-interactive bash where BASH_ENV
> is the only thing that is sourced. (Or so I've heard
> - I don't use bash myself - I use zsh, where you
> solve this by putting shared stuff in .zshenv)
>
> So try putting the shared file path in BASH_ENV, or
> you can even try:
>
> BASH_ENV=~/.bashrc emacs
Yes, this works for me even tho I'm on zsh.
In ~/.bashrc put this, carefully, as bash is fussy!
function hi () {
echo hello
}
Then invoke Emacs like this:
SHELL=/bin/bash BASH_ENV=~/.bashrc emacs -Q
Then:
M-x shell-command RET hi RET
N.B. Don't rely on SHELL if you want to change the
shell in general.
--
underground experts united
http://user.it.uu.se/~embe8573
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: executing bash function with shell-command
[not found] <mailman.14548.1456191752.841.help-gnu-emacs@gnu.org>
@ 2016-02-24 21:52 ` mvar
2016-02-25 0:11 ` Emanuel Berg
0 siblings, 1 reply; 5+ messages in thread
From: mvar @ 2016-02-24 21:52 UTC (permalink / raw
To: help-gnu-emacs
> Emanuel Berg <embe8573@student.uu.se> writes:
>
> Yes, this works for me even tho I'm on zsh.
>
> In ~/.bashrc put this, carefully, as bash is fussy!
>
> function hi () {
> echo hello
> }
>
> Then invoke Emacs like this:
>
> SHELL=/bin/bash BASH_ENV=~/.bashrc emacs -Q
>
> Then:
>
> M-x shell-command RET hi RET
>
> N.B. Don't rely on SHELL if you want to change the
> shell in general.
>
> --
> underground experts united
> http://user.it.uu.se/~embe8573
hello Emanuel,
yes this works perfectly fine and even with --daemon!
many thanks!
Michael
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: executing bash function with shell-command
2016-02-24 21:52 ` mvar
@ 2016-02-25 0:11 ` Emanuel Berg
0 siblings, 0 replies; 5+ messages in thread
From: Emanuel Berg @ 2016-02-25 0:11 UTC (permalink / raw
To: help-gnu-emacs
mvar <mvar.40k@gmail.com> writes:
> yes this works perfectly fine and even with
> --daemon!
>
> many thanks!
My pleasure!
--
underground experts united
http://user.it.uu.se/~embe8573
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-02-25 0:11 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-22 19:58 executing bash function with shell-command mvar
2016-02-23 0:27 ` Emanuel Berg
2016-02-23 0:34 ` Emanuel Berg
[not found] <mailman.14548.1456191752.841.help-gnu-emacs@gnu.org>
2016-02-24 21:52 ` mvar
2016-02-25 0:11 ` Emanuel Berg
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.