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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ksh: variable is gone when function is piped to tee

Status
Not open for further replies.

w5000

Technical User
Nov 24, 2010
223
PL

Hello,
could anyone please explain why variable DIR1 disappears in script2 (when functions f1/f2 are "piped" to tee command)?

Code:
# cat ddd
#!/usr/bin/ksh

f1 () {
DIR1=/mnt/swt
echo inside f1 DIR1 is ${DIR1}
}

f2 () {
echo inside f2 DIR1 is ${DIR1}
}

f1
echo outside f1 DIR1 is $DIR1
f2

# ./ddd
inside f1 DIR1 is /mnt/swt
outside f1 DIR1 is /mnt/swt
inside f2 DIR1 is /mnt/swt
#



Code:
# cat ddd
#!/usr/bin/ksh

f1 () {
DIR1=/mnt/swt
echo inside f1 DIR1 is ${DIR1}
}

f2 () {
echo inside f2 DIR1 is ${DIR1}
}

f1 | tee -a /tmp/log1
echo outside f1 DIR1 is $DIR1
f2 | tee -a /tmp/log1

# ./ddd
inside f1 DIR1 is /mnt/swt
outside f1 DIR1 is
inside f2 DIR1 is
#


 
I think that if a function is "piped" then it is executed in a subshell.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top