LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Sysdate setting in bash_profile (https://www.linuxquestions.org/questions/linux-newbie-8/sysdate-setting-in-bash_profile-798558/)

malickhat 03-29-2010 01:05 AM

Sysdate setting in bash_profile
 
Hi,
this is my situation,I'm taking backup for some files in that i need to append the sysdate so that i can easily identify which file has to restore at some point,I've tried the following
In my bash_profile(RHEL4)
Code:

SYSDATE=`%d/%m/%Y`
export SYSDATE

i tried after relogin to another terminal ,but when i give the following command
Code:

[malick@home ~]$ echo $SYSDATE

[malick@home ~]$ source ~/.bash_profile
bash: fg: %d/%m/%Y: no such job

I don't know what to do ,once the sysdate is set i can add that element to my script where it takes the back up

catkin 03-29-2010 01:15 AM

Try
Code:

SYSDATE="$( date '+%d/%m/%Y' )"
Notes:
  • %d/%m/%Y is a format string for the date command (except it needs a leading +).
  • ` ` is deprecated in favour of $( ) for reasons given here.
  • Putting it in double quotes ensures that the whole string is assigned to SYSDATE in the unexpected event that output from the date command includes any whitespace.

malickhat 03-29-2010 01:39 AM

Quote:

Originally Posted by catkin (Post 3916247)
Try
Code:

SYSDATE="$( date '+%d/%m/%Y' )"
Notes:
  • %d/%m/%Y is a format string for the date command (except it needs a leading +).
  • ` ` is deprecated in favour of $( ) for reasons given here.
  • Putting it in double quotes ensures that the whole string is assigned to SYSDATE in the unexpected event that output from the date command includes any whitespace.

Hi,
It's working but for half of my requirement ,it's giving me the current date but not with the exact timestamp,like if i logged in a shell the SYSDATE is set as constant value rather than the sync with the clock .so the SYSDATE is always same after i logged in .i need something eactly matches as same as that of date command


All times are GMT -5. The time now is 02:51 AM.