Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fish Shell: Chaining commands to be run as a background job

I'd like to be something along the following at the fish command prompt:

$ sleep 120; and echo 'buggery bollocks' &

Or, as of fish 3.0:

$ sleep 120 && echo 'buggery bollocks' &

Or either of the above without the trailing ampersand, then suspending with Ctrl-Z and putting the whole thing into the background with 'bg' command. None of these work. The first two just do the sleep in the foreground, and I assume the echo in the background. If I suspend with Ctrl-Z, then 'buggery bollocks' gets output immediately.

I know I could just write a script with those two commands in it, and run it in the background, but I feel I shouldn't have to. Any experienced fishmongers around who might have an answer for me?

Thanks!

like image 465
tinskip Avatar asked Oct 25 '25 03:10

tinskip


2 Answers

Fish does not currently support backgrounding anything more complicated than a simple external command.

So as of fish 3.1.2 (and most likely 3.2.0): Yes, you have to write a script with those two commands in it and run it in the background.

like image 79
faho Avatar answered Oct 27 '25 16:10

faho


As @faho said fish doesn't support background processes yet, but there is a "hackish" way to do it.

fish -c 'my_command_1' & fish -c 'another_cmd' & fish -c '3rd_cmd' 

I use this to start browser-sync and upload scripts in 1 cmd when I develop.

like image 25
konung Avatar answered Oct 27 '25 18:10

konung



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!