passing a variable to the `date` command

passing a variable to the `date` command

Post by g_spe.. » Sat, 09 Sep 2000 00:22:50



Is there a way to pass a variable to the `date` function or another
function that would return a specific value based upon the format I
request?

Ex.
     If I pass "8" I would want the function to return "Aug" for August
     If I pass "09072000" I want `Thursday` returned.

so on and so forth.

Gary Sperano

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

passing a variable to the `date` command

Post by Mason » Sat, 09 Sep 2000 03:39:14



>Is there a way to pass a variable to the `date` function or another
>function that would return a specific value based upon the format I
>request?

>Ex.
>     If I pass "8" I would want the function to return "Aug" for August
>     If I pass "09072000" I want `Thursday` returned.

>so on and so forth.

start with man cal
do some parsing using awk, grep, cut, ...
and hopefully you'll get what you want.

 
 
 

passing a variable to the `date` command

Post by Ken Pizzi » Sat, 09 Sep 2000 17:04:33



>Is there a way to pass a variable to the `date` function or another
>function that would return a specific value based upon the format I
>request?

>Ex.
>     If I pass "8" I would want the function to return "Aug" for August
>     If I pass "09072000" I want `Thursday` returned.

>so on and so forth.

This is easy using mktime
(http://www.interlog.com/~john/technogeek/source/mktime):
  mktime -m 8 -F %b
  mktime -m 09 -d 07 -y 2000 -F %A

or GNU's implementation of date
(mirrors of ftp://ftp.gnu.org/gnu/sh-utils/):
  date -d 8/1 +%b
  date -d '2000-09-07' +%A

How to go about generalizing the mktime example is, I think,
clear enough; the GNU date version is probably less obvious,
so I'll show it:
  date -d "$month/1" +%b
  date -d "$year-$month-$day" +%A

As to the magic "%b" and "%A" formats --- I'll leave you to
the documentation.

                --Ken Pizzini

 
 
 

1. need help passing date to variable

Hi,
I'm trying to pass the current month and day to a variable for puposes
of renaming and archiving files. Here's the basic idea;

#!/bin/sh
v_date= date +%m%d
mv file "file$v_date"

I've tried various combinations of single and double quotes on both
lines with no success. Any help is greatly appreciated. Thanks in
advance,
Larry

2. MetroX and CL 5446 - Chipset unknown?

3. CSH: passing "date" 's output to a @ variable.

4. Compilation problem with C++ code !!!

5. Passing variables as arguments to commands in a shell script

6. Diald&squid

7. Passing variable values to commands

8. HELP PLEASE !!!

9. Passing variables on the command line to a bash script

10. grabbing variables from command "date"

11. date command and rolling date forward to y2000

12. Date command not setting date

13. How can I pass a command line argument to an aliased command?