After running ./executable-file $MYPATH is not visible anymore since the source-command has been executed in a different shell. If I remove the shebang I get "./executable-file: line 1: setenv: command not found".
How can I source a file in the running shell with the help of a command?
> After running ./executable-file $MYPATH is not visible anymore since > the source-command has been executed in a different shell. If I remove > the shebang I get "./executable-file: line 1: setenv: command not > found".
> How can I source a file in the running shell with the help of a > command?
[...]
If you're shell is csh compatible, use
source executable-file
If not, maybe what you're after is something like:
eval "$(csh -c 'source source-file; sh -c export\ -p')"
(assuming "sh" is a POSIX sh; on Solaris, you need PATH=$(getconf PATH):$PATH export PATH to pick the correct sh).
I don't want to use the "source" command from the prompt. I would like to just start an executable file and this should set some environment variables and modify my $PATH in the running shell.
> I forgot to mention that I use a csh on a RHEL 4.6 machine.
> On 9 Mai, 17:07, Stephane CHAZELAS <this.addr...@is.invalid> wrote: >> 2008-05-9, 07:25(-07), amiro...@googlemail.com: >> [...]
>> If you're shell is csh compatible, use
>> source executable-file
> I don't want to use the "source" command from the prompt. I would like > to just start an executable file and this should set some environment > variables and modify my $PATH in the running shell.
[...]
You can't. The environment is a list of strings that is passed as an argument to the execve() system call, so that some data of the original command can survive into the new execed command.
If you want your shell memory to be updated, it must be something initiated by your shell. Typically a process can't alter the memory of another process, that would cause all sorts of reliability and security issues.
What you can do is something like:
eval `executable`
and manage to have "executable" display some csh code. But the fact that csh has got a number of issues wrt quoting is going to make it difficult to do reliably.
> I forgot to mention that I use a csh on a RHEL 4.6 machine.
> On 9 Mai, 17:07, Stephane CHAZELAS <this.addr...@is.invalid> wrote: >> 2008-05-9, 07:25(-07), amiro...@googlemail.com: >> [...]
>> If you're shell is csh compatible, use
>> source executable-file
> I don't want to use the "source" command from the prompt. I would like > to just start an executable file and this should set some environment > variables and modify my $PATH in the running shell.
As has already been said, you can't do that with a command implemented as an executable file. However, with most shells such as sh, ksh, zsh and bash, you can do that with an alias or a function defined in your shell's rc file. There's probably some equivalent mechanism in csh, but I don't know anything about csh.
You source the file in your current shell, not in a script.
You can 1) type source file 2) create an alias alias S "source file" and then type S You can combine this by using alias DOIT "source file;mycommand" and type DOIT 3) You can execute "source file" by adding that line in your .cshrc
Then for each new window or shellyou start up, you execute the command that changes your environment variable.
I usually use something like
# this is your ~/.cshrc file--------------- if ( ! ( $?USER && $?prompt && $?TERM )) exit
# This command is only executed in interactive shells attached #to terminals.
if ( -f file ) source file
4) Just put setenv MYPATH /my/path in your ~/.cshrc file or your ~/.login file