Score:0

Error in console when open a web browser from a bash script

dk flag

Im trying to write a very simple script. It should to open a web-browser (www.google.com for instance), wait for 3 seconds and kill the web-browser. What happens to me is that seems that the script do not pass from this first step.

#!/bin/bash

/usr/bin/google-chrome "http://www.google.com/"
echo "Hello"
sleep 3
pkill chrome

Not even showing the "Hello" in the terminal. Only the web-browser opens and no more happens.

What am I missing?

Thanks in advance.

muru avatar
us flag
Your script won't proceed until the `google-chrome` process you started exits (this might happen immediately if there's an already running Chrome process, in which case your `google-chrome` command will simply ask that process to open a new tab). You need to start it in the background for the script to be able to proceed to the remaining commands.
PonJar avatar
in flag
@muru is correct. I think you can achieve what you want by adding an & at the end of command to start `google-chrome`
RRR CCC avatar
dk flag
Thanks for answering guys. The command google-chrome runs and open the Chrome window, but remains there. Is like the .sh does not noticed that the Chrome has opened finally. I mean, the Chrome window opens and loads the url, but does not start the second line command. Maybe is missing any kind of return OK from the first command to follow with the echo "Hello". What do you think?
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.