unset CBI_LINUX
if [[ -f /etc/os-release ]]; then
CBI_LINUX=$(grep -E "^PRETTY_NAME=" /etc/os-release | sed -E 's/^PRETTY_NAME="//' | sed 's/ Linux //' | sed -E 's/[ .].*//')
CBI_LINUX=${CBI_LINUX,,}
fi
unset CBI_LINUX; if [[ -f /etc/os-release ]]; then CBI_LINUX=$(grep -E "^PRETTY_NAME=" /etc/os-release | sed -E 's/^PRETTY_NAME="//' | sed 's/ Linux /_/' | sed -E 's/[ .].*//'); CBI_LINUX=${CBI_LINUX,,}; fi
On CentOS 7, it gives:
$ echo $CBI_LINUX
centos7
and on Rocky 8, it gives:
$ echo $CBI_LINUX
rocky8
Lua
local f = io.open("/etc/os-release", "r")
if f ~= nil then
f:close()
for line in io.lines("/etc/os-release") do
if (string.sub(line, 1, 13) == 'PRETTY_NAME="') then
line = string.sub(line, 14, string.len(line))
line = string.lower(line)
line = line:gsub(" linux ", "")
line = line:gsub("[ .].*", "")
CBI_LINUX = line
break
end
end
end
print(CBI_LINUX)
Lmod
-- Set environment variable CBI_LINUX to 'centos7' or 'rocky8'
if mode() == "load" then
if os.getenv("CBI_LINUX") == nil then
if isFile("/etc/os-release") then
execute{cmd = "CBI_LINUX=$(grep -E '^PRETTY_NAME=' /etc/os-release | sed -E 's/^PRETTY_NAME=\"//' | sed 's/ Linux //' | sed -E 's\
/[ .].*//'); CBI_LINUX=${CBI_LINUX,,}", modeA = {"load"}}
end
end
elseif mode() == "unload" then
execute{cmd = "unset CBI_LINUX", modeA = {"unload"}}
end
Bash
On CentOS 7, it gives:
and on Rocky 8, it gives:
Lua
Lmod