linux - 如何通过 bash 在 Linux Mint 中查询运行 bash 脚本的虚拟桌面的编号?
问题描述
环境:
Linux Mint, Cinnamon desktop manager, with multiple workspaces=virtual desktops, e.g. 4.
Bash script
已知情况:
How to determine the number of workspaces:
wmctrl -d | wc -l
我需要的:
Get the number of virtual desktops the bash script is running on with a pure bash as var (like with grep, not awk or similar) and echo the var.
解决方案
使用awk
(恕我直言仍然是手头任务最合适的选择):
nr_of_active_workspace=$(wmctrl -d | awk '/\*/{print $NF}')
echo $nr_of_active_workspace
或pure bash
解决方案:
nr_of_active_workspace=$(wmctrl -d | while read -r line; do [[ $line =~ '*' ]] && echo ${line: -1} ; done)
echo $nr_of_active_workspace
推荐阅读
- c# - 为什么单击客户端时我的 DatePicker (BunifuUI) 不显示?
- .net - 如何使用 Graph API 获取仅在全局地址列表中可见的电子邮件组列表?
- google-sheets - 如何更改坐标的颜色?
- flutter - Flutter textformfield 底部有 2 行
- android - 在我的 react native expo 应用程序中,我可以在哪里找到或设置 Firebase 的 applicationID?
- sql - Sql 语句获取每月未下订单的客户(同时显示月份)
- api - 微服务 API URL 模式
- python - 用python中的匹配替换所有出现
- android - 使用约束布局等间距的四个图像
- testing - 如何同时测试多个用户?