Search code examples
linuxluareadlinebsd

Determine what exactly returns parameter


In some OS, like Ubuntu, Debian, etc. cal return current calendar with highlighting of today. And cal -h turns off highlighting of today:

screenshot

But in some OS, like Arch Linux -h param displays the help of a calendar.

I'm doing a small script with Lua:

function foo()
    local f, err = io.popen('cal -h', 'r')
    if f then
        local s = f:read("*all")
        f:close()
        return s
    else
        return err
    end
end

And my main question - how do I determine exactly what specifically returned parameter -h?


Solution

  • Execute cal -h and parse the output for the word "help". If the word is found, the "-h" is for help. If word not found it is likely used to mean highlight but there is no sure way of knowing (a way that will work on all flavors of Linux). Most likely you will need some code to read environment var that identifies platform so you can issue correct command and rely on users of different Linux flavors to report when default fails and report to you the correct command line parameters. OTOH you could limit supprt to only those platforms you have access to. Or combination of these approaches.