Page 1 of 1
Inserting comment within a broken line - is it possible? [WORKAROUND]
Posted: 02 Jul 2023 11:57
by DOSadnie
I have broke my A-OK working last line of a certain big script into
Code: Select all
robocopy "%sd%" "%dd%\%folder_name%" /E ^
/XF "%sd%\desktop.ini"
and it still works
But if I try adding
or
in-between those two lines then the whole script breaks
So it there a way to comment between them, i.e. in a separate line, or it is just plan impossible?
Re: Inserting comment within a broken line - is it possible?
Posted: 02 Jul 2023 14:12
by OJBakker
Not a real comment but you can hide your comment in a non-existent variable followed by the line-continuation caret.
The my comment part must still be valid cmd syntax.
Code: Select all
@echo on
cls
dir c:\ ^
%==my comment==% ^
/one
pause
An other option is to use a null character to hide your comment from cmd.
Everything on the line following a null character including the CRLF that ends the line will be completely ignored by cmd.
You will need an additional line-continuation caret at the line following your comment.
Code: Select all
@echo on
cls
dir c:\^
X(replace X with character x"00") my comment or whatever you want to write in this line
^
/one
pause
Re: Inserting comment within a broken line - is it possible?
Posted: 03 Jul 2023 03:43
by DOSadnie
These do seem like nice tricks. But such lines will not be clearly visible - thus do only half the job
With the first approach I could start such comment with something standing out like >>█<< sign and thus arriving at something like
Code: Select all
robocopy "%sd%" "%dd%\%folder_name%" /E ^
%==███ MY COMMENT==% ^
/XF "%sd%\desktop.ini"
However apparently I cannot use
to make it more obvious to what it is as it breaks the script- so I will think if I prefer it over making e.g.
as an intro to the line with the actual comment, which [when forced] will be placed over a block consisting of a broken line; because there is also a possibility that signs other than >>:<< in such line can brake the script
As for the second approach, this
Code: Select all
robocopy "%sd%" "%dd%\%folder_name%" /E ^
MY COMMENT
^
/XF "%sd%\desktop.ini"
renders my script half-workihg, because it only creates a backup of the folder structure omitting all of the files
Re: Inserting comment within a broken line - is it possible?
Posted: 03 Jul 2023 10:47
by miskox
Maybe you could write comments like this:
Code: Select all
robocopy "%sd%" "%dd%\%folder_name%" /E /XF "%sd%\desktop.ini"
REM | | | | |
REM | | | | \- comment 1
REM | | | \----------- comment 2
REM | | \-------------- comment 3
REM | \-- comment 4 (not right justifed)
REM \-- comment 5 (not right justifed for example)
Saso
Re: Inserting comment within a broken line - is it possible?
Posted: 04 Jul 2023 03:42
by DOSadnie
Now that is a neat workaround - but also time consuming, the more elements from a single line a user wants to comment on
Thank you both for you help
Re: Inserting comment within a broken line - is it possible?
Posted: 04 Jul 2023 04:18
by miskox
DOSadnie wrote: ↑03 Jul 2023 03:43
renders my script half-workihg, because it only creates a backup of the folder structure omitting all of the files
I think the reason why it will not work is this:
will work. But if I add a comment:
Code: Select all
some_command /a /b^
REM some comment
/c /d
equals to:
Code: Select all
some_command /a /b REM some comment /c /d
some_command will see this new parameter as invalid.
Saso
Re: Inserting comment within a broken line - is it possible?
Posted: 04 Jul 2023 04:19
by miskox
DOSadnie wrote: ↑04 Jul 2023 03:42
...but also time consuming...
I guess not because you usually do it only once.
Saso
Re: Inserting comment within a broken line - is it possible?
Posted: 05 Jul 2023 01:27
by LaverneReeves
In your case, when you add the comment line using either :: or REM, the caret is interpreted as an escape character, causing the script to break.
Re: Inserting comment within a broken line - is it possible?
Posted: 09 Jul 2023 22:56
by miskox
Here is a test:
Code: Select all
@echo off
echo ---------- sort by extension
dir /b /oe
echo ---------- sort by extension does not work
dir /b
REM comment
/oe
echo ----------end
Code: Select all
c:\temp>test.cmd
---------- sort by extension
test.cmd
3.pdf
2.pdf
1.pdf
---------- sort by extension does not work
1.pdf
2.pdf
3.pdf
test.cmd
'/oe' is not recognized as an internal or external command,
operable program or batch file.
----------end
c:\temp>
And what could happen is that if your qualifier/parameter is a valid command it will run:
Code: Select all
some_program.exe these are parameters
and now let's insert a comment:
Code: Select all
some_program.exe these are^
REM comment
parameters
If there is a program named 'parameters' it will run.
Saso