Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to echo an echo command into a new file?

I'm trying to use a batch file to create another batch file... it's a file I have to use quite often with a few variables changed each time. I'm running into an issue because in the batch I'm trying to create, it is also using echo to write to a .txt file.

Here is the command:

echo echo %date% - %time% >> C:\MOVEit\Logs\FileGrabberLog.txt >> C:\filegrabber_%org%.bat

I want to enter the whole string echo %date% - %time% >> C:\MOVEit\Logs\FileGrabberLog.txt into C:\filegrabber_%org%.bat.

I can put "" around it but then they appear in the batch I'm trying to create.

Anyone know of a way around this?

like image 708
iesou Avatar asked Dec 06 '11 15:12

iesou


2 Answers

You escape % with %% and other special characters with ^ so this should work;

echo echo %%date%% - %%time%% ^>^> C:\MOVEit\Logs\FileGrabberLog.txt >> C:\filegrabber_%org%.bat
like image 105
Alex K. Avatar answered Oct 23 '22 17:10

Alex K.


Or to avoid the carets you can use disappearing quotes

setlocal EnableDelayedExpansion
(
  echo !="!echo %%date%% - %%time%% >> C:\MOVEit\Logs\FileGrabberLog.txt
) > C:\filegrabber_%org%.bat

Only the percents have to be doubled then.

It works, as the !="! is parsed in the special character phase, and it is decided, that the rest of the line will be quoted.

And in the delayed phase the !="! will be removed, as the variable with the name =" does not exist (and it can't be created).

like image 32
jeb Avatar answered Oct 23 '22 18:10

jeb