-   Linux - General (
-   -   how to echo whole string to a file? (

dwarf007 06-19-2007 11:26 PM

how to echo whole string to a file?
Is there anyone know how to echo whole string to a file?

I am trying to echo the below sting into a file, but the output will be DATETIME=070620115242

DATETIME=`date +"%y%m%d%H%M%S"`

Appreciate someone can help on this : )

SlackDaemon 06-19-2007 11:43 PM

Use the redirection operators > or >>. The latter will append to a file while the first will overwrite its contents:

DATETIME=`date +"%y%m%d%H%M%S"`
echo DATETIME=$DATETIME > file.txt

dwarf007 06-20-2007 12:00 AM

It still occurs the same output in the file "DATETIME=070620121353"

I need the below exact line exist in the file.
DATETIME=`date +"%y%m%d%H%M%S"`

Is there any way to do it?

SlackDaemon 06-20-2007 12:11 AM

echo 'DATETIME=`date +"%y%m%d%H%M%S"`' > file.txt

notice both ` and ' were used

dwarf007 06-20-2007 02:38 AM

Thanks a lot, it works now.
Appreciate your help so much : )

Dr_Death_UAE 06-20-2007 03:44 AM

btw, "echo -n > filename" will empty the file.

All times are GMT -5. The time now is 06:42 AM.