Google Groups Home
Help | Sign in
Sourcing file in the same shell using a command and csh
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
amirovic@googlemail.com  
View profile
(1 user)  More options May 9, 10:25 am
Newsgroups: comp.unix.shell
From: "amiro...@googlemail.com" <amiro...@googlemail.com>
Date: Fri, 9 May 2008 07:25:17 -0700 (PDT)
Local: Fri, May 9 2008 10:25 am
Subject: Sourcing file in the same shell using a command and csh
Hi,

How can I solve the following scenario:

/--- source-file ---
| setenv MYPATH /my/path
\-----------------------

/--- executable-file ---
| #!/bin/csh
| source source-file
\-----------------------------

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?

Thanks and regards,
Amir


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stephane CHAZELAS  
View profile
(1 user)  More options May 9, 11:07 am
Newsgroups: comp.unix.shell
From: Stephane CHAZELAS <this.addr...@is.invalid>
Date: Fri, 9 May 2008 17:07:59 +0200 (CEST)
Local: Fri, May 9 2008 11:07 am
Subject: Re: Sourcing file in the same shell using a command and csh
2008-05-9, 07:25(-07), amiro...@googlemail.com:
[...]

[...]

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).

--
Stéphane


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
amirovic@googlemail.com  
View profile
 More options May 9, 11:57 am
Newsgroups: comp.unix.shell
From: "amiro...@googlemail.com" <amiro...@googlemail.com>
Date: Fri, 9 May 2008 08:57:11 -0700 (PDT)
Local: Fri, May 9 2008 11:57 am
Subject: Re: Sourcing file in the same shell using a command and csh
Hi,

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.

Thanks,
Amir


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stephane CHAZELAS  
View profile
 More options May 9, 12:07 pm
Newsgroups: comp.unix.shell
From: Stephane CHAZELAS <this.addr...@is.invalid>
Date: Fri, 9 May 2008 18:07:42 +0200 (CEST)
Local: Fri, May 9 2008 12:07 pm
Subject: Re: Sourcing file in the same shell using a command and csh
2008-05-9, 08:57(-07), amiro...@googlemail.com:
> 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.

Do you have to use csh?

--
Stéphane


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gary Johnson  
View profile
 More options May 9, 1:41 pm
Newsgroups: comp.unix.shell
From: Gary Johnson <garyj...@eskimo.com>
Date: 9 May 2008 17:41:29 GMT
Local: Fri, May 9 2008 1:41 pm
Subject: Re: Sourcing file in the same shell using a command and csh

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.

--
Gary Johnson


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Maxwell Lol  
View profile
 More options May 9, 9:05 pm
Newsgroups: comp.unix.shell
From: Maxwell Lol <nos...@com.invalid>
Date: 09 May 2008 21:05:02 -0400
Local: Fri, May 9 2008 9:05 pm
Subject: Re: Sourcing file in the same shell using a command and csh

"amiro...@googlemail.com" <amiro...@googlemail.com> writes:
> How can I solve the following scenario:

> /--- source-file ---
> | setenv MYPATH /my/path
> \-----------------------

> /--- executable-file ---
> | #!/bin/csh
> | source source-file
> \-----------------------------

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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google