[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: "source" shell commands
From: |
Barry Margolin |
Subject: |
Re: "source" shell commands |
Date: |
Sat, 24 Mar 2007 11:24:54 -0400 |
User-agent: |
MT-NewsWatcher/3.5.2 (PPC Mac OS X) |
In article <85wt16btg5.fsf@lola.goethe.zz>, David Kastrup <dak@gnu.org>
wrote:
> Tassilo Horn <tassilo@member.fsf.org> writes:
>
> > Matthew Flaschen <matthew.flaschen@gatech.edu> writes:
> >
> >> Is there an elisp function to "source" a shell file; i.e. an
> >> alternative to:
> >>
> >> (shell-command (concat "source \"" (expand-file-name "~/.rc") "\""))
> >
> > Sure.
> >
> > --8<---------------cut here---------------start------------->8---
> > (defun mf-source (file)
> > (interactive "f")
> > (shell-command (concat "source \"" file "\"")))
> > --8<---------------cut here---------------end--------------->8---
>
> Quoting is always good for trouble. I'd rather use
>
> (defun mf-source (file)
> (interactive "f")
> (call-process shell-file-name nil nil nil "source" file))
>
> assuming that you don't care about the output.
First of all, shells don't take a command line to execute as arguments.
Take a look at what happens if you try it from the command line:
$ bash source .bashrc
source: source: No such file or directory
You can do it with the -c option, but then they expect the command to be
in a single argument:
(call-process shell-file-name nil nil nil
"-c" (format "source '%s'" file))
Second, the point of "sourcing" is to execute the commands in the
current process's context. Since call-process and shell-command both
execute a child process, nothing that occurs in the sourced script will
have any effect on the emacs process. So even if you get the syntax
right, it won't do anything different from executing the script normally.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
- "source" shell commands, Matthew Flaschen, 2007/03/24
- Re: "source" shell commands, Tassilo Horn, 2007/03/24
- Re: "source" shell commands, David Kastrup, 2007/03/24
- Re: "source" shell commands,
Barry Margolin <=
- Re: "source" shell commands, Matthew Flaschen, 2007/03/24
- Re: "source" shell commands, Matthew Flaschen, 2007/03/24
- Re: "source" shell commands, Peter Dyballa, 2007/03/25
- Re: "source" shell commands, Matthew Flaschen, 2007/03/25
- Re: "source" shell commands, Peter Dyballa, 2007/03/25
- Re: "source" shell commands, Matthew Flaschen, 2007/03/25
- Re: "source" shell commands, Peter Dyballa, 2007/03/26
- Re: "source" shell commands, Matthew Flaschen, 2007/03/26
- Message not available
- Re: "source" shell commands, Tim X, 2007/03/25
- Re: "source" shell commands, Matthew Flaschen, 2007/03/25