LinuxQuestions.org

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

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 01:12 AM.