0

So I am creating a Batch Operating System, but the problem is... IT KEEPS SAYING MISSING OPERATOR!!

Here is a snippet of my code:

@echo off

 title LiME - Version 1.0 
 mode con: cols=86 lines=21

 if exist "\SystemLiME" goto startup.jsc

   ) else (

 if not exist "\SystemLiME" goto boot.jfk


 :boot.jfk

cls

echo                                         MAINBOOTCONFIG                                        

echo.

echo CHECKING FOR VOLUMES TO CREATE..

ping localhost -n 5 >nul

 if exist "\SystemLiME" set create-vol1=0

  ) else (

 if not exist "\SystemLiME" set create-vol1=1

 if exist "\SystemLiME\pkgs" set create-vol2=0

  ) else (

 if not exist "SystemLiME\pkgs" set create-vol2=1

 if %create-vol1% == 0 set /a count-vol-create=0
 if not %create-vol1% == 0 set /a count-vol-create=%count-vol-create%+=1

 if %create-vol2% == 0 set /a count-vol-create=%count-vol-create%+=0
 if not %create-vol2% == 0 set /a count-vol-create=%count-vol-create%+=1

 echo %count-vol-create%
 pause

But what I'm focusing on is this:

:boot.jfk

 cls

 echo                                         MAINBOOTCONFIG                                        

 echo.

 echo CHECKING FOR VOLUMES TO CREATE..
 ping localhost -n 5 >nul

 if exist "\SystemLiME" set create-vol1=0

  ) else (

 if not exist "\SystemLiME" set create-vol1=1

 if exist "\SystemLiME\pkgs" set create-vol2=0

  ) else (

 if not exist "SystemLiME\pkgs" set create-vol2=1

 if %create-vol1% == 0 set /a count-vol-create=0
 if not %create-vol1% == 0 set /a count-vol-create=%count-vol-create%+=1

 if %create-vol2% == 0 set /a count-vol-create=%count-vol-create%+=0
 if not %create-vol2% == 0 set /a count-vol-create=%count-vol-create%+=1

 echo %count-vol-create%
 pause

Everytime I start this code, I get 'Missing operator.' 'Missing operator.' 'ECHO is off.' 'Press any key to continue...'

please help me!! :'( (btw, im new to stackoverflow :) )

SomethingDark
  • 13,229
  • 5
  • 50
  • 55

1 Answers1

0

Use this batch code as replacement for second posted batch code:

:boot.jfk
cls
echo                                         MAINBOOTCONFIG
echo/
echo CHECKING FOR VOLUMES TO CREATE..
%SystemRoot%\System32\ping.exe localhost -n 5 >nul
if exist "\SystemLiME" ( set "CreateVol1=0" ) else ( set "CreateVol1=1" )
if exist "\SystemLiME\pkgs" ( set "CreateVol2=0" ) else ( set "CreateVol2=1" )
if %CreateVol1% == 0 ( set "CountVolCreate=0" ) else ( set /A "CountVolCreate+=1" )
if not %CreateVol2% == 0 set /A CountVolCreate+=1
echo %CountVolCreate%
pause

For the reason of using echo/ instead of echo. to output an empty line see DosTips forum topic
ECHO. FAILS to give text or blank line - Instead use ECHO/

Specify in batch files executables like ping with full path and with file extension to make the batch file independent on the current values of the environment variables PATH and PATHEXT.

See the answers on IF ELSE syntax error within batch file? and batch scripting - if exist ./sdcard/file.any using adb

The string after set /A is interpreted as arithmetic expression on which each whitespace/operator delimited string is interpreted automatically as variable name whose current value should be converted to a 32-bit signed integer for evaluation of the expression. Therefore it is not needed to use immediate variable expansion using %VariableName% or delayed variable expansion using !VariableName! in an arithmetic expression because just VariableName is enough even within a command block, except the variable name contains spaces or dashes or other operators.

For that reason it is not good to use variable names containing dashes when using such variables in an arithmetic expression as the dash could be interpreted as minus operator. The usage of CamelCase naming notation is in general best for variable names in batch files. Variables with CamelCase names can be easily read and searched/replaced in batch files and are surely never mixed up with text output with echo or within a remcomment line as for example on having the following command lines in a batch file:

@echo off
rem Assign batch file name to a variable.
set "BatchFileName=%~nx0"
echo Batch file name is: %BatchFileName%
set "BatchFileName="

An arithmetic expression should contain always only one equal sign. A syntax like variable=variable+=1 is definitely not right. Right is either variable=variable+1 or shorter variable+=1.

Read the answer on Why is no string output with 'echo %var%' after using 'set var = text' on command line? for an explanation why usage of set "variable=value" is recommended for the definition (or deletion) of an environment variable. On an arithmetic expression where whitespaces are just delimiters it is usually not needed to use syntax set /A "variable=expression", but there are exceptions like the one in line 9 of batch code above.

Please note that if exist "\SystemLiME" means if there is a directory or file with name SystemLiME in root of current drive. If you want to exclude file names and check for existence of a directory append a backslash on directory path. And if you want to check for existence of the directory in current directory remove the backslash at beginning of the path.

:boot.jfk
cls
echo                                         MAINBOOTCONFIG
echo/
echo CHECKING FOR VOLUMES TO CREATE..
%SystemRoot%\System32\ping.exe localhost -n 5 >nul
if exist "SystemLiME\" ( set "CreateVol1=0" ) else ( set "CreateVol1=1" )
if exist "SystemLiME\pkgs\" ( set "CreateVol2=0" ) else ( set "CreateVol2=1" )
if %CreateVol1% == 0 ( set "CountVolCreate=0" ) else ( set /A "CountVolCreate+=1" )
if not %CreateVol2% == 0 set /A CountVolCreate+=1
echo %CountVolCreate%
pause

This batch code checks for existence of the directories SystemLiME and SystemLiME\pkgs in current directory in comparison to above batch code which checks for existence of file or directory SystemLiME and file or directory pkgs in directory SystemLiME in root of current drive.

For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.

  • cls /?
  • echo /?
  • if /?
  • pause /?
  • ping /?
  • set /?
Mofi
  • 46,139
  • 17
  • 80
  • 143