help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "source" shell commands


From: Matthew Flaschen
Subject: Re: "source" shell commands
Date: Sun, 25 Mar 2007 00:03:10 -0400
User-agent: Thunderbird 1.5.0.10 (X11/20070306)

Tim X wrote:
> Matthew Flaschen <address@hidden> writes:
> 
>> Barry Margolin wrote:
>>> In article <address@hidden>, David Kastrup <address@hidden> 
>>> wrote:
>>>
>>>> Tassilo Horn <address@hidden> writes:
>>>>
>>>>> Matthew Flaschen <address@hidden> 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.
>> Thanks.  I realized this after I asked the question.  Is there any way I
>> could import the variables after?  I found
>> shell-copy-environment-variable but I reall want to copy *all* of them
>> (for when I start emacs from outside the shell).
>>
> 
> I doubt shell-copy-environment-variable will work either. As soon as the sub
> process that executes the "source file" has exited, I think that envrionment 
> is
> gone. 
> 
> I'm curious, how are you starting emacs "from outside the shell"?

Maybe I'm missing something big.  I'm using KDE.  Sometimes I start
emacs from an xterm (Konsole actually), but sometimes I just click a
shortcut.

> The first and easiest is to change the shell that executes your
> .Xsession (or equivalent) to a login shell.

Any idea how I would do that in Ubuntu (gNewSense really)?

Matthew Flaschen




reply via email to

[Prev in Thread] Current Thread [Next in Thread]