1、打开终端,复制输入如下命令upower 颍骈城茇-i $(upower -e | grep 'BAT') | grep -E "state|to\ full|percentage"
2、按下回车,执行命令,就可以看到电池状态了
3、其中state表示是否在充电,dischraging表示没有连接电源充电,charge表示正在充电percentage表示电池剩余百分比
4、可以把终端命令写入sh文件,以后调入shell脚本程序,就可以查江冤有鲩询电池信息了echo 'upower -i $(upower -e | grep 'BAT') | grep -E "state|to\ full|percentage"'>battery.sh
5、为battery.sh添加执行权限chmod +x battery.sh
6、输入 ./battery 执行batter.sh脚本