Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can i export a command from batch file

Status
Not open for further replies.

baruch

MIS
Mar 2, 2000
59
IL
Hello

who can i export a command to the prompet shell

For exmp. A=`echo "d home"

(now i want than after the batch will end, the command

will be executed and the prompet kerenel will switched to home.

thanx
barry
 
thanx hemo

I wrote in pc program that has file inpun like this:

s /data/source
br /home/baruch
u /user/bin
...

it called cdn with parameter of the first 2 characteres of
the input file, for exmp. cdn br.

the output of that program is "cd /home/baruch".

in unix the cd only efected on the shell scripet and
after exit to the kernel the prmpt didn't switched to the
disaire folder.

who can i do that in unix evairoment.

thanx for advance

Barry
 
S="/data/source"
BR="/home/baruch"
U="/user/bin"
export S BR U
-----

cd $S
cd $BR
cd $U

The 'export' command will export the variables so they can be used after the shell program exits.

I recommend using uppecase monikers, since a lot of nonsense seeming lowercase ones may actually be unix commands and you could get unexpected results.

Is this more of what you are looking for?

Having a shell script physically move you to a new folder and then exit, leaving you in the new directory.. I've not done that other than spawning a new shell in the new directory, when exiting a shell, I am always left in the directory I called the original shell from.
 
Thanx agtan hemo
First sorry for my poor english....
I will give u other example.
1. i have a sh scrept like this. (called a).

A="/home/val" ;export A
cd $A
pwd

2. from the my prompt korn shell:

/abic0/prgmrs/baruch> sh -x a
+ A=/home/val
+ export A
+ cd /home/val
+ pwd
/home/val
/abic0/prgmrs/baruch>

3. My target was to be physically after exit scipt a
in the koren shell prompt, in /home/val directory.

4. in pc dos, i have a nice tool like bookmark.
directories i want frequent switch to them.
i have a txt file like above, and a cobol program
called CDN, that can execute pc command from inside,
so when i type CDN m , the dos prompt switched to c:\ms.

Most gegarts to your attention,
Barry
most regards

Barry
 
The command /abic0/prgmrs/baruch> sh -x a

forks a child process.

A child process can never modify the parent environment.

The cd $a in the child process, is lost as soon as the child process exits.

If you want to run a script that modifies the parent process, you need to "source" , or "dot" execute the script.

You do this by:-

. a

HTH

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top