Linux检索监视器名称
情况:我正在使用多个监视器,我想用bash来获取它们的名称.目前,我正在使用Ubuntu 10.04.
Situation: I'm using multiple monitors and I want to get their names in bash. Currently I'm using Ubuntu 10.04.
我了解xrandr.从中我只能得到统计数据.我想要的是读取数组中的所有监视器名称以使用它们.
I know about xrandr. From it I can get only statistics data. What I want is to read all monitor names in an array to work with them.
是否有一种清晰的方法可以在不删除某种字符串名称的情况下做到这一点?一种清晰的方法是从文件中读取它们.一种不清楚的方法是将xrandr输出传递给某种函数以从中删除名称.
Is there a clear way to do that without cutting names from some kind of string? A clear way would be reading them from file. A not clear way would be to pipe xrandr output to some sort a function to cut names out from it.
sudo get-edid
对我不起作用.(现在可以在另一台计算机Lubuntu 14.10上运行;我要怪BIOS的差异,但这是一个随机的猜测...)
sudo get-edid
didn't work for me. ( now works on another computer, Lubuntu 14.10; I'd blame BIOS differences but that's a random guess...)
无论如何在X下, xrandr --verbose
都会打印EDID块.这是一种提取它并传递给 parse-edid
的快捷方法:
Anyway under X, xrandr --verbose
prints the EDID block. Here is a quick and dirty way to extract it and pass to parse-edid
:
#!/bin/bash
xrandr --verbose | perl -ne '
if ((/EDID(_DATA)?:/.../:/) && !/:/) {
s/^\s+//;
chomp;
$hex .= $_;
} elsif ($hex) {
# Use "|strings" if you dont have read-edid package installed
# and just want to see (or grep) the human-readable parts.
open FH, "|parse-edid";
print FH pack("H*", $hex);
$hex = "";
}'