![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#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 |
|
#3
|
|||
|
|||
|
plz, forget my previous post. I think I was still sleeping...
Chris |
|
#4
|
|||
|
|||
|
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. |
|
#5
|
||||
|
||||
|
Quote:
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. |
|
#6
|
|||
|
|||
|
OK, it is true, you can find in this forum an answer for each UNIX question. Thanks a lot!
|
|||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|