dgo
dgo

Reputation: 3937

Batch file `@` symbol results in error

I have a batch file that I am trying to get working and I'm having trouble suppressing the output of a couple of commands. One solution I've tried is to start the commands with the @ symbol - (something I've done sucessfully plenty of times). Here is the code:

@echo off
setlocal
for /f "tokens=*" %%i in (tmp\hdata.txt) do (

    ::' just a note - hdata.txt contains lines of text such as,
    ::' for example:
    ::' jquery_javascript_32
    ::' underscore_javascript_9
    ::' I couldn't do this with simple delimiters because some lines are like:
    ::' underscore_js_javascript_43

    set "id=%%i"
    set filewithnum=!id:_javascript_=!

     ::' *** BELOW throws error ***
     @echo !filewithnum!|findstr /R "[0-9]$" && set "file=!filewithnum:~,-1!" >nul 2>&1

     ::' *** BELOW throws error ***
     @echo !filewithnum!|findstr /R "[0-9]$" && set "file=!file:~,-1!" >nul 2>&1

    echo !file!

)

endlocal
exit /b    

The lines commented above throw: '@echo' is not recognized as an internal or external command, operable program or batch file.

Seems weird.

Any ideas as to what's happening here?


Note: The extra ' after the comment :: above is to make syntax highlighting work properly on stackoverflow.

Upvotes: 3

Views: 355

Answers (1)

Klitos Kyriacou
Klitos Kyriacou

Reputation: 11621

Once you've fixed the points Magoo raised in the comments, you need to suppress the output of findstr. You don't need @ since command echo mode is already turned off at the start of the script.

You've got this:

@echo !filewithnum!|findstr /R "[0-9]$" && set "file=!filewithnum:~,-1!" >nul 2>&1

So you are redirecting the output of the set command! To redirect the output of findstr, do this:

echo !filewithnum!|findstr /R "[0-9]$" >nul 2>&1 && set "file=!filewithnum:~,-1!"

Upvotes: 3

Related Questions