我需要编写一个脚本来启动终端模拟器并在其中运行特定的命令。由于我不知道目标系统上安装了哪些终端仿真器,我如何才能找到安装了哪些终端仿真器?
我看过这个线程。但是,我并不是很倾向于进行硬编码检查,我正在寻找通用解决方案。
我提出了这个非常肮脏的黑客,但我真的不确定这会如何:
termdetect
:
#!/bin/bash
IFS=:
for i in $PATH; do
find "$i" -type f -exec isterminal {} \;
done
Run Code Online (Sandbox Code Playgroud)
isterminal
:
#!/bin/bash
if [[ ! -z "$1" ]]; then
if [[ "$(head -c 4 "$1")" == $'\x7fELF' ]]; then
if ! grep editor "$1" > /dev/null; then
if grep -E '(vte_terminal_|libutempter|rxvt_)' "$1" > /dev/null; then
echo "$1"
fi
fi
fi
fi
Run Code Online (Sandbox Code Playgroud)
是否有我可能缺少的简单通用解决方案?或者我除了搜索二进制文件以获取提示或使用硬编码列表之外别无他法?