Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are correct that it's a simple problem. In fact it is solved with the introduction of 4 characters, all the same one.</p> <p>Exposing a backslash in batch is a bad idea, it's likely to confuse the interpreter into thinking that it's dealing with an actual file or path. You should surround it with double-quotes. This is true with other characters, including !%&amp;*?/\&lt;>,. mostly special characters that deal with paths and files. There may be more, and some are only occasionally a problem. Even 1 and 2 can cause trouble when next to a redirection character.</p> <p>Just to let you know, neither <code>setlocal</code> or the delayed expansion notation <code>!</code> are necessary here, although there is no harm in it. (Except that the delayed notation makes debugging harder as it did in this case, by showing, when ECHO is On, the variable name rather than it's contents.)</p> <p>Also, when trimming the last character of a string you don't need 0 in <code>:~0,-1</code>, using <code>:~,-1</code> is sufficient. Though there is no harm in doing it either way.</p> <p>And lastly, the <code>echo on</code> is unnecessary, as <code>echo on</code> is the default. <code>Echo On</code> is more for just displaying small parts of the execution of a long file. Though, once again, there is no harm in it.</p> <pre><code>@echo on setLocal EnableDelayedExpansion ::set firstline to firstline of test.txt set /p firstline=&lt;test.txt ::Remove trailing slash if present ::Your error is below this IF "!firstline:~-1!"=="\" SET firstline=!firstline:~,-1! ::Output firstline (without \ to new txt file) echo !firstline!&gt;test2.txt endlocal </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload