Skip to content

Commit c57e9d4

Browse files
committed
Handle sh and dash shells
1 parent e06c378 commit c57e9d4

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

lib.ring

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -734,11 +734,20 @@ class SysInfo {
734734
shellInfo = SysGet("SHELL")
735735
// Get shell name only from its path e.g. /usr/bin/fish --> fish
736736
shell[:name] = JustFileName(shellInfo)
737-
// Execute the shell with the version argument to retrieve the shell version
738-
shellVersion = systemCmd(shellInfo + " --version")
737+
// Initialize shellVersion
738+
shellVersion = "Unknown"
739+
// Skip version check for sh and dash shells since they don't support --version
740+
if !(shell[:name] = "sh" or shell[:name] = "dash") {
741+
// Execute the shell with the version argument to retrieve the shell version
742+
shellVersion = systemCmd(shellInfo + " --version")
743+
}
739744

740745
// Switch statement to determine the shell type and extract its version
741746
switch shell[:name] {
747+
case "sh"
748+
shell[:version] = systemCmd("strings $(which dash) | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+' | head -n1")
749+
case "dash"
750+
shell[:version] = systemCmd("strings $(which dash) | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+' | head -n1")
742751
case "bash"
743752
// Find the position of the version number in the shellVersion string
744753
versionPos = substr(shellVersion, "version ") + len("version ")

0 commit comments

Comments
 (0)