我想用 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/