Re: What does :$(cal) do?
From: Noel R. Nihill (nnihil01_at_Motorola.BLAH.com)
Date: Thu, 19 Jun 2003 16:18:16 +0100
"Paul" <email@example.com> wrote in message
> I have written the following script to calculate the number of days
> left until the end of the current month.
> this_day=`date +%d`
> days_left=`expr $last_day - $this_day`
> I copied the :$(cal) bit from another script I found on the net.
> I was wondering if anyone can explain in general terms what this type
> of command/technique is called, and also what it is doing.
':' expands to '/bin/true' in ksh, and $(cal) is the same as `cal`,
i.e. 'replace cal with cal's stdout'. So what you have is:
/bin/true June 2003 S M Tu W Th F S 1 2 3 4 5...<snip>...30
And of course '$_' expands as the last parameter given to the last
executed command, which in this case will be the date of the last
day of the current month.
Note that if cal did not output a tab first of all, this would break with
an error like 'ksh: :June: not found'. Observe:
# :$(cat /etc/system)
ksh: :*ident: not found
> Also, is there any other common usage for this technique.
I don't know, mind you.
> I know it works OK, I am just interested in the theory.
> Thanks in advance.
-- Noel R. Nihill UNIX® platform development Motorola NSS I *could* be arguing in my spare time.