Exporting variables from subshell to parent shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Exporting variables from subshell to parent shell
# 1  
Old 11-23-2009
Exporting variables from subshell to parent shell

Hi,
I was trying to do something where I would be able to export one local variable in a telnet subshell to its parent shell.

I found something like this over here, but couldnt exactly understand it Smilie.
I am referring to this part actually:
Code:
#! /usr/bin/ksh
exec 4>&1
tail -5 >&4 |&
exec >&p
cat /etc/passwd
exitcode=$?
exec >&- >&4
wait
echo exitcode = $exitcode
exit 0

Can someone pls provide me with some explanation of the above or provide me with some link where things like exec 4>&1 and all are explained in proper detail?
Thanks.
# 2  
Old 11-23-2009
Hi.

To export the variable value to its parent shell you can use:
Code:
#!/bin/ksh

.  subshell

and subshell:

Code:
#!/bin/ksh

export variable="value"

# 3  
Old 11-23-2009
Quote:
Originally Posted by King Nothing
Can someone pls provide me with some explanation of the above or provide me with some link where things like exec 4>&1 and all are explained in proper detail?
Thanks.
A useful link:

I/O Redirection

Regards

Last edited by Franklin52; 11-23-2009 at 03:39 AM..
# 4  
Old 11-23-2009
page 102, bash beginner's guide, tldp.org
# 5  
Old 11-23-2009
Those page are about bash and so ksh's interactive coprocess and the two-way pipe are not explained there. This book explains this well: Learning the Korn Shell, Second Edition, otherwise man ksh.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Exporting Values of Variables to Another File

Hello, I'm very new to Linux, and I have a question, I'm hoping you could help me with. :) I have created a file called subject, contains this code: #!/bin/bash read -p "Student Name: " NAME read -p "Student ID: " ID read -p "Address: " ADDRESS I'm to create another file called... (7 Replies)
Discussion started by: iwant2learn
7 Replies

2. Shell Programming and Scripting

How to export a variable from a subshell to the parent shell?

A not-too-ugly solution to this classic problem... #!/bin/bash mknod fifo p ( echo 'value' > fifo & ) VARIABLE=`cat fifo` rm fifo Whatdcha think? Good? No good? (9 Replies)
Discussion started by: vomv1988
9 Replies

3. Shell Programming and Scripting

Exporting data as a CSV file from Unix shell script

Friends...This is the first time i am trying the report generation using shell script... any suggestions are welcome. Is there a way to set the font size & color when i am exporting the data from unix shell script as a CSV file ? The following sample data is saved as a .csv file in the... (2 Replies)
Discussion started by: appu2176
2 Replies

4. Shell Programming and Scripting

Kill a process from parent shell within a shell script

Hi, I am looking for a solution for the following problem: Im Using tcpdump within a shellskript started in a subshell by using brackets: ( /usr/sbin/tcpdump -i ... -c 1 ) - I want the outout of tcpdump saved in a variable - Than tcpdump-Process in the Subshell should be killed - and I... (6 Replies)
Discussion started by: 2retti
6 Replies

5. Shell Programming and Scripting

full path of a file situated either in parent's dir. or parent's parent dir. so on...

hi experts(novice people can stay away as it is no child's game), i am developing a script which works like recycle bin of windows. the problem i am facing is that when ever i am trying to delete a file which is situated in parent directory or parent's parent directory i am unable to... (1 Reply)
Discussion started by: yahoo!
1 Replies

6. Shell Programming and Scripting

parent shell is waiting upon the child shell

Hi, I haev to devlop a script which when executed will take in a sudo privelege and run a set of commands then will go back to parent shell and execute the rest of the command But the problem I am facing is that when the script is executed it takes the sudo privelege but it waits for the... (0 Replies)
Discussion started by: ruchirmayank
0 Replies

7. Shell Programming and Scripting

How to change parent shell's variables?

I have a question about how to change variables in parent shell. My script, test.sh, is below: #!/bin/sh # test.sh PATH=. The commands I ran for test: $ echo $PATH .:/usr/bin:/usr/sbin:/usr/local/sbin: $ sh test.sh $ echo $PATH .:/usr/bin:/usr/sbin:/usr/local/sbin: ... (1 Reply)
Discussion started by: pankai
1 Replies

8. UNIX for Dummies Questions & Answers

Passing environment variables to parent shells

Hi, I am using bash and need to run a set of tcsh scripts that set environment variables. Is there a way to do this? Any help greatly appreciated. (3 Replies)
Discussion started by: konndanley
3 Replies

9. Shell Programming and Scripting

How to pass CSH variables up to the parent?

Hi .. I have a dynamic script called from a programming language called Powerhouse (4GL). The module, called QUIZ, allows the user to call shell commands from within it... i.e. !rm -f mipss156t2cmd1.bat mipss156t2tmp1.txt !printf '#!/bin/csh\n' > mipss156t2cmd1.bat !printf 'setenv... (0 Replies)
Discussion started by: ElCaito
0 Replies

10. Shell Programming and Scripting

exporting variables (shell scripting)

Hi, i've got an executable shell script, called mysc.sh with this line only: export DATASIZE=0 i run it from my console (./mysc.sh), and after that in the console i run: echo $DATASIZE and nothing prints what could be the problem??? thanks!! (2 Replies)
Discussion started by: kfad
2 Replies
Login or Register to Ask a Question