The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
problem with dd command or maybe AFS problem Anta Shell Programming and Scripting 0 08-25-2006 07:10 AM
SSH Problem auth problem budrito UNIX for Advanced & Expert Users 1 03-17-2004 07:12 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 02-18-2004
Registered User
 

Join Date: Feb 2002
Posts: 23
tee problem

Hi you,

This the code I have:

function show_menu {

echo " lalalalal"
echo " 1. ...."
echo " 2. ...."
echo " 3. exit"
read choice

case $choice in
1) ... ;;
2) ...;;
*) stop=1;;
esac

}

##main
while [ ! $stop ]; do
show_menu | tee -a event.log
done

before I added the tee command to generate a log file, this worked perfectly. But with tee, the loop will never end, because stop will never change to 1.
Could you explain me why?
How can I solve this?
Even when I add an 'exit 1' instead of stop=1 it won't work!

Thanks for any help.

Ben Sky
Reply With Quote
Forum Sponsor
  #2  
Old 02-18-2004
Registered User
 

Join Date: Feb 2004
Location: The Netherlands
Posts: 2
Ben,

I'm not sure but why do you use a tee. If I were you is would redirect the output to the logfile.

...
show_menu >> event.log
...

Greetings,

Chris
Reply With Quote
  #3  
Old 02-18-2004
Registered User
 

Join Date: Feb 2004
Location: The Netherlands
Posts: 2
plz, forget my previous post. I think I was still sleeping...

Chris
Reply With Quote
  #4  
Old 02-18-2004
Registered User
 

Join Date: Feb 2002
Posts: 23
I got a solution for my problem, I put the while loop into the show_menu function.
But it is still not clear for me why my old approach does not work.
Reply With Quote
  #5  
Old 02-18-2004
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
Quote:
Originally posted by bensky
But it is still not clear for me why my old approach does not work.
The command:
show_menu
works the way you think it works. You invoked a function and the current shell can run it. When stop is changed inside the function, it affects the main shell's copy of "stop".

But:
show_menu | tee -a event.log
is a pipeline. Now a subshell must be spawned to run show_menu. And the function is changing the private version of "stop" in the subshell.

ksh is the only shell that I know that can run the last command of a pipeline in the current shell. This allows stuff like
echo hello | read variable
to work. But I don't know of any shell that can run the rest of a pipeline in the current shell.

See this post for another approach.
Reply With Quote
  #6  
Old 02-18-2004
Registered User
 

Join Date: Feb 2002
Posts: 23
OK, it is true, you can find in this forum an answer for each UNIX question. Thanks a lot!
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 08:47 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0