Re: background command within function

Lawrence Velázquez <[email protected]>
Newsgroups gmane.comp.shells.zsh.user
Message-ID <[email protected]>
On Tue, Dec 17, 2024, at 8:54 PM, Ray Andrews wrote:
> gg()
> {
>     imwheel
>     /opt/GeoGebra-Linux-Portable-5-2-853-0/geogebra-portable $@ &
>     imwheel -k -q
> }
>
> ... I like to background things where I can, but in this case the 
> function continues to execute and 'imwheel -k  -q' gets run even before 
> geogebra is quit.

Yes, that is how asynchronous lists work.

	When a sublist is terminated by `;' or newline, the shell
	waits for it to finish before executing the next sublist.
	If a sublist is terminated by a `&', `&|', or `&!', the
	shell executes the last pipeline in it in the background,
	and does not wait for it to finish (note the difference
	from other shells which execute the whole sublist in the
	background).  A backgrounded pipeline returns a status of
	zero.

https://zsh.sourceforge.io/Doc/Release/Shell-Grammar.html#Simple-Commands-_0026-Pipelines

> I think I'm wanting to have my cake and eat it too, 
> but just in case, can I have both?  -- I get my prompt back, but the 
> final command is not run until I quit geogebra?

Have the function run its commands synchronously, but invoke the
function itself asynchronously.

	% gg() { imwheel; geogebra-portable "$@"; imwheel -k -q }
	% gg &

-- 
vq
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.