LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   how to echo whole string to a file? (http://www.linuxquestions.org/questions/linux-general-1/how-to-echo-whole-string-to-a-file-563118/)

dwarf007 06-20-2007 12:26 AM

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-20-2007 12:43 AM

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 01: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 01:11 AM

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

notice both ` and ' were used

dwarf007 06-20-2007 03:38 AM

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

Dr_Death_UAE 06-20-2007 04:44 AM

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


All times are GMT -5. The time now is 12:56 PM.