LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Unable to print Timestamp (https://www.linuxquestions.org/questions/linux-newbie-8/unable-to-print-timestamp-785532/)

sowraj 01-29-2010 01:03 AM

Unable to print Timestamp
 
Hi,

I am just trying to print the timestamp. which is not working.

#!/bin/bash

TSTAMP= date '+%d.%m.%y-%H:%M:%S'
echo "${TSTAMP}"


It is not displaying anything.

Can some body pls tell me what is wrong with the above commands.

bohemistanbul 01-29-2010 02:55 AM

Hi

use that character before and after command : `
and also no whitespace character after = character
the command should be :

#!/bin/bash

TSTAMP=`date '+%d.%m.%y-%H:%M:%S'`
echo ${TSTAMP}

sowraj 01-29-2010 05:53 AM

Problem in displaying timestamp
 
Quote:

Originally Posted by bohemistanbul (Post 3844583)
Hi

use that character before and after command : `
and also no whitespace character after = character
the command should be :

#!/bin/bash

TSTAMP=`date '+%d.%m.%y-%H:%M:%S'`
echo ${TSTAMP}

I tried it.

If i give ` character before and after the command it is giving an error
date '+%d.%m.%y-%H:%M:%S : not found

date '+%d.%m.%y-%H:%M:%S command is working in the terminal.. why is it not working in the shell script.

evo2 01-29-2010 06:02 AM

Did you add the trailing ' ?

Also, since your post explicitly states the shell is bash, you can use:

Code:

#!/bin/bash
TSTAMP=$(date '+%d.%m.%y-%H:%M:%S')
echo ${TSTAMP}

Evo2.


All times are GMT -5. The time now is 04:27 PM.