Open and then close a program in bash

I’m trying to get a simple script working.

I want to open firefox, wait 10 seconds, then close firefox

my script is

!#/bin/bash
firefox && sleep 10 && wmctrl -c firefox

however, this just:

1 - gives me an error message

(process:5133): GLib-CRITICAL **: g_slice_set_config: assertion 'sys_page_size == 0' failed

2 - then starts firefox

BUT

3 - doesn’t sleep

4 - doesn’t close firefox

I’m not at my machine, and I’m a bash beginner, but I think sleep is waiting for Firefox to exit before starting.

Try something like:

firefox & sleep 10 pkill firefox

2 Likes

that worked a treat!

thanks a lot :relaxed:

As long as each command is on a separate line, I don’t even think you need the “&” do you?

As in:

firefox
sleep 10
killall firefox

Edit to add:

Ahhh…i see you fixed it anyway…:slight_smile:

2 Likes

thanks steve.

i really should read my Linux Command Line book, but i’m too busy learning other stuff!

so many languages, so little time!

1 Like