linux - bash 脚本打开 chrome 然后在 chrome 关闭时关闭计算机

标签 linux bash wait

我想用 bash 编写一个启动脚本,使 ubuntu 盒子对爷爷更友好。

脚本应该:

打开 Chrome 等到 chrome 关闭 关闭计算机

目前为止

#!/bin/bash
if [ -z "$1" ]; then
    address="http:\\www.google.co.uk"
else
    address=$1
fi

echo starting the internet
google-chrome $address

while [ 1=1 ];
do
   grep_resp=$(ps aux | grep chrome)
   if [ -z "$grep_resp" ]; then
       echo turning computer off 
   else
       echo chrome still running
   fi
   sleep 5
done 

但是“chrome”的 grep 在进程列表中

有什么帮助吗?

最佳答案

你得到那个错误是因为 $grep_resp 在这...

if [ -z $grep_resp ]; then

...可能扩展为包含空格的字符串。如果你在它周围加上引号:

  if [ -z "$grep_resp" ]; then

它会如您所愿。但是,我认为所有这些可能都是不必要的。 Chrome 在运行时不会自动后台运行,因此您应该可以这样做:

google-chrome $address
echo turning computer off
...

关于linux - bash 脚本打开 chrome 然后在 chrome 关闭时关闭计算机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10488920/

相关文章:

linux - 如何使用 Shell 脚本验证 IP 是否被特定服务器使用?

linux - Linux 上是否还存在 Thundering Herd 问题?

linux - "rsyslogd"占用170M内存正常吗?

python - 等到页面刷新

php - 如何在 AWS Linux/CentOS 上使用 Yum 更新 PHP 版本

linux - 在服务器端使用 bash 代替 PHP/Perl 或 Java

bash - 无法将 shopt globstar 输出保存到变量

regex - 使用复杂正则表达式的 Grep

java - JOptionPane : Display button "Ok" after a certain amount of time

performance - 民意调查好还是等待好?