LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-03-2006, 10:41 AM   #1
fawqati
LQ Newbie
 
Registered: May 2006
Posts: 5

Rep: Reputation: 0
! HELP ! Script : How to control parent shell ???


Dear Someone that can help,

I have a simple yet seemingly impossible issue.

I would like to export an environement variable and change the current working directory. The tough part is i need this to effect the current shell where the script was invoked. Ideally, I would like to use a bourne shell script to implement this.

I do understand the implications involved in that the shell forks a child. But there must be a way of achieving what i need.

Here is the script background :

###########################################################
User invokes from anywhere lets say for example

$Prompt > pwd ### /home/smith/
$Prompt > myproject.sh ### runs this script


#!/usr/bin/sh
echo" Please enter Project Name = \c"
read MYANSWER
MYPROJECT_NAME = "$MYANSWER"
MYPROJECT_HOME = "/project/$MYANSWER"
export MYPROJECT_NAME
export MYPROJECT_HOME
cd $MYPROJECT_HOME

back to prompt i frustratingly get
$Prompt > pwd ### /home/smith/
$Prompt > env ### does NOT contain the variables

How do i make it effect the current shell ? Can i stop it forking or can i force back something to the parent ? Anything, anyone please help !!!!
###########################################################
 
Old 06-03-2006, 12:58 PM   #2
vls
Member
 
Registered: Jan 2005
Location: The grassy knoll
Distribution: Slackware,Debian
Posts: 192

Rep: Reputation: 31
Write it as a function or use the 'source' builtin (AKA .)

source yourscript or . yourscript, same thing.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Run script on every file contained within a parent directory and its subdirectories General Programming 4 05-15-2006 02:12 AM
I made a shortcut to a shell script and it is using default shell icon... shlinux Linux - Software 2 04-20-2006 06:29 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM
Control over parent of processes? Sinope Linux - General 0 09-27-2004 12:20 AM
Shell Script to control logins NIkss Programming 9 12-17-2003 12:53 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration