using date in a variable name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting using date in a variable name
# 8  
Old 02-13-2006
Hi I got this to work with tar -cvf `date %m%d%y`
I basically took out the variable assignment.
However it is a hidden file. I need to do an ls -f to see it. Any idea how to fix this?

Thanks,

Phil
# 9  
Old 02-13-2006
that's weird.

the backtick is nothing more than the output from the commands executed in between them.

when i run:

today=`date +%m%d%y`
echo $today

i get '021306'.

that being the case... i changed it and did...

today="`date +%m%d%y`.tar"
tar -cvf $today ./ # tarring just the current dir tree to see if it works

...and everything worked fine... and tarred the files/dirs into 021306.tar

i don't know what kind of system you're using, but i've tried this on windows (Cygwin bash), Linux (Red Hat bash), and AIX (ksh) and got the same results.

don't know why it would be a hidden file. sorry... i wish i had more insight.
# 10  
Old 02-14-2006
MySQL

Hey Thanks Gents,
I was putting a space after the = in my variable definition. It works fine with out the space. I am use to using a debugger of some sort.

Thanks, again

Phil
# 11  
Old 02-14-2006
ah yes, the infamous "space" char. i've accidentally done that MANY time. yes, a debugger would be nice, wouldn't it? you can, however, look into the "-x" flag with ksh which will pretty much show you all your vars, etc. as your script steps through each line.
# 12  
Old 02-14-2006
Quote:
TODAY= date +%m%d%y
echo $TODAY ### it echo's 021606 which is fine
The first line is the same as just
date +%m%d%y
and it produced the display that looked correct. Prepending "TODAY= " is legal to most commands and it temporarily set TODAY equal to nothing during the execution of the date command. This was a no-op since the date command does not use the value of TODAY. When we get the second line, we echo the current value of TODAY which apparently was nothing perhaps because the variable was otherwise unset. The OP saw the output from the first command and mistook is for the output from the second command. For debugging use statements like:
echo TODAY = $TODAY
to avoid this and other problems.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to replace a parameter(variable) date value inside a text files daily with current date?

Hello All, we what we call a parameter file (.txt) where my application read dynamic values when the job is triggered, one of such values are below: abc.txt ------------------ line1 line2 line3 $$EDWS_DATE_INSERT=08-27-2019 line4 $$EDWS_PREV_DATE_INSERT=08-26-2019 I am trying to... (1 Reply)
Discussion started by: pradeepp
1 Replies

2. Shell Programming and Scripting

Convert a date stored in a variable to epoch date

I am not able to pass date stored in a variable as an argument to date command. I get current date value for from_date and to_date #!/usr/bin/ksh set -x for s in server ; do ssh -T $s <<-EOF from_date="12-Jan-2015 12:02:09" to_date="24-Jan-2015 13:02:09" echo \$from_date echo... (7 Replies)
Discussion started by: raj48
7 Replies

3. Shell Programming and Scripting

How to get date value by variable?

Hello All, I have one question: > cat abc.txt BrSp_IVR_Daily_Report_last_day_,date +'%Y-%m-%d',jim,969-PP-A,DAILY,/home/jim/reports/,YES BrSp_Status_Movements_C_,date +'%Y-%m-%d',jim,969-PP-A,DAILY,/home/jim/reports/,YES > cat akk.ksh #!/bin/ksh get_data() { OLDIFS=$IFS IFS="," ... (2 Replies)
Discussion started by: Ak1983
2 Replies

4. Solaris

Setting Date Variable +1 date

I need to set a date varable within ksh that will set the date to the next day in the format 25-JUL-2013 - any help would be appreciated. (3 Replies)
Discussion started by: bjdamon
3 Replies

5. Shell Programming and Scripting

LINUX ---> Add one date to a date variable

Hi All, I am trying to add one day to the busdt variable i am extracting from a file (DynamicParam.env). I am deriving the busdt as below. Is there any function which I can use to derive as below. If busdt=20120910, then the new derived variable value should be 20120911 If... (2 Replies)
Discussion started by: dsfreddie
2 Replies

6. Shell Programming and Scripting

Date into variable

I'm trying to set var j = to date like this: j = $(date +%yy%m%d) echo $j But I'm missing something here. (3 Replies)
Discussion started by: dba_frog
3 Replies

7. Shell Programming and Scripting

[ask]date variable

Is there date variable in bash? for example, I have string 01-23-2010 (mm-dd-yyyy) or 23-01-2010 (dd-mm-yyyy). How can I convert that string to date variable? and how to do some math operation based on date? for example, today is 12-11-2010. I want to know date 100 days after today or 50... (3 Replies)
Discussion started by: 14th
3 Replies

8. Shell Programming and Scripting

How to check date variable according to the current date?

Hi folks, I need to write a script that should activate a process according to the current hour. The process should be activatet only if the hour is between midnight (00:00) and 07:00. How should I create the condition? Thanks in advance, Nir (2 Replies)
Discussion started by: nir_s
2 Replies

9. Shell Programming and Scripting

convert date variable to doy variable

Hello: I have a script that requires the use of DOY (as a variable) instead of YY/MM/DD. I already obtained these parameters from downloaded files and stored them as variables (i.e. $day, $month, $year). Is there any simple script that I could incorporate in mine to do this job? Regards, ... (8 Replies)
Discussion started by: aabrego
8 Replies

10. Shell Programming and Scripting

Date variable

Dear all, Today=`date +%d%m%y`` I want to decrease the date by 1. How would we do that. Thanks. (6 Replies)
Discussion started by: asadlone
6 Replies
Login or Register to Ask a Question