0

I wanted to put a calendar in a file so I ran:

$ ncal -CMh > file.txt

But instead I received the following:

Usage: cal [general options] [-hjy] [[month] year]
       cal [general options] [-hj] [-m month] [year]
       ncal [general options] [-bhJjpwySM] [-s country_code] [[month] year]
       ncal [general options] [-bhJeoSM] [year]
General options: [-NC31] [-A months] [-B months]
For debug the highlighting: [-H yyyy-mm-dd] [-d yyyy-mm]

I was surprised because I was sure the command is correct. I thought perhaps, getopts options are not permutable like I thought so I tried reordering the options. However all permutations that didn't have -C before -M worked:

$ ncal -hC
$ ncal -Ch
$ ncal -hM
$ ncal -Mh
$ ncal -MCh
$ ncal -MhC
$ ncal -hMC
$ ...

My theory is that when ncal enters cal mode using -C it loses the -M option probably because -M didn't exist in original cal. I have no idea if this is correct or not.

Why does this happen?

This is on latest Debian Jessie.

3

The usage message shows the valid options for cal and ncal:

Usage: cal [general options] [-hjy] [[month] year]
       cal [general options] [-hj] [-m month] [year]
       ncal [general options] [-bhJjpwySM] [-s country_code] [[month] year]
       ncal [general options] [-bhJeoSM] [year]
General options: [-NC31] [-A months] [-B months]

After a -C flag, you can only use general options or valid cal options, until an -N flag switches back to ncal mode, after which you can use general options or valid ncal options. Until another -C flag switches back to cal mode, and so on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.