tags:

views:

143

answers:

3

I have tried prefixing lines with semicolons, 'REM', etc.. but no matter what when I run my batch file I keep getting "unknown command REM whatever"

+4  A: 

If you're talking about cmd.exe batch files under Windows, you can use:

rem this method or
:: this method.

For bash and a lot of other UNIX-type shells, you use:

# this method.

I'm pretty certain you're not using cmd.exe since that would give you an error like:

'rem' is not recognized as an internal or external command,
operable program or batch file.

rather then:

Unknown command ...

If you are using a UNIX-type shell, the # character is almost certainly what you're after. If you let us know exactly the shell you're using, we can probably help out further.

paxdiablo
Keep in mind that `::` sometimes has unintended consequences within blocks. I've seen weird error messages about unknown drives but couldn't recreate them on recent versions of Windows.
Joey
I haven't seen any problem with that but then I don't write *huge* batch files. They mostly tend to have comments before a block to explain what's going on, and my blocks don't get that big before the contents of the blocks are refactored into a call statement.
paxdiablo
Its cmd.exe, standard windows shell.I put "REM test" (without quotes) into a file called test.bat, navigate to it and type "test" and press enter (within cmd.exe), I get "REM" output to my console and nothing else.
Josh Ribakoff
That's to be expected. Unless you prefix the command (`rem` in this case) with an `@` or turn off echoing the command to the console with `echo off` you will see every line in the batch file printed to the console. It doesn't do anything, though since it's a comment.
Joey
+2  A: 

"REM test" It is not recognized, and it is windows vista. I simply get "rem" output back to my console.

That's entirely normal behavior. Batch files are simply sequences of commands that are run one after another. So every line will get output to the console as if it were typed there.

H:\>echo rem test > test.cmd

H:\>test

yields the output

H:\>rem test

as if I typed rem test directly to the console.

You can suppress this by either prefixing the line with @:

@rem test

or by including echo off in the batch file:

@echo off
rem test

If I put ":: test" and execute it I get back "Test".

Can't reproduce here.

If I put "; test" it recursively executes itself

A semicolon at the start of the line seemingly gets ignored.

Joey
No it is cmd.exe
Josh Ribakoff
That was it! Sounds familiar too.
Josh Ribakoff
A: 

you probably created an UNICODE file. These files contain 2 bytes header named BOM which is not shown by any editor but cmd attempts to execute them and fails.

To make sure this is indeed an issue: type any other command at the very beginning of your file and see it throws the same error - for example @echo test

To fix it, just create a new plain text file and copy content of the original file there. then remove the original file and replace it by the newly created one.

Moisei