PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Sourcing file in the same shell using a command and csh
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Sourcing file in the same shell using a command and csh

Réponse
 
LinkBack Outils de la discussion
Vieux 09/05/2008, 15h25   #1
amirovic@googlemail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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 of a
command?

Thanks and regards,
Amir
  Réponse avec citation
Vieux 09/05/2008, 16h07   #2
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Sourcing file in the same shell using a command and csh

2008-05-9, 07:25(-07), amirovic@googlemail.com:
[...]
> 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 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).

--
Stéphane
  Réponse avec citation
Vieux 09/05/2008, 16h57   #3
amirovic@googlemail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
  Réponse avec citation
Vieux 09/05/2008, 17h07   #4
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Sourcing file in the same shell using a command and csh

2008-05-9, 08:57(-07), amirovic@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
  Réponse avec citation
Vieux 09/05/2008, 18h41   #5
Gary Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Sourcing file in the same shell using a command and csh

amirovic@googlemail.com <amirovic@googlemail.com> wrote:
> 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.


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
  Réponse avec citation
Vieux 10/05/2008, 02h05   #6
Maxwell Lol
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Sourcing file in the same shell using a command and csh

"amirovic@googlemail.com" <amirovic@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

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 13h38.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,13584 seconds with 14 queries