Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: suspend (^Z) behavior while a function is running is unclear



On 2012-02-20 10:53:01 -0800, Bart Schaefer wrote:
> As a hack, one could do:
> 
>     alias -g NOSUSP='|while { read -rE } { : }'
> 
>     foreach foo (a b c) { print $foo; sleep 5 } NOSUSP

OK, I could do:

  alias Z='while { read -rE } { : }'

and use '|Z', which is shorter and should be safe.

But there are several problems:

1. The left-hand side is run in a subshell, so that side effects
   (e.g. setting a variable) are not taken into account. Wanting
   to disable TSTP was the main reason to avoid this problem!

2. One still has two processes (I wanted to avoid any additional
   process).

3. Buffering, e.g.: { echo -n a; sleep 2; echo b } |Z
   The 'a' isn't visible immediately.

4. The "while" terminates with a nonzero exit status (I could locally
   unsetopt PRINT_EXIT_VALUE, though).

5. I sometimes get a spurious additional newline.

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)



Messages sorted by: Reverse Date, Date, Thread, Author