Minificar batch

Asked

Viewed 62 times

0

Is there any kind of batch command or software to minify files .batch ?

Just like exists with Minify to minify files .js or .css

2 answers

1


Unfortunately not, because .batch are commands executed sequentially, different from .js that is multi-paradigma, and the .css is interpreted by browser, searching for already predefined files.

In summary, the .Batch or .sh cannot be minified.

  • Is there at least the possibility to encrypt the batch ?

0

Hello.

A possible solution is being explained below to simulate one minified script.

First of all, bounce that the mini-style need to be used only in specific cases, because it is a practice that removes the clear code (clear code), making maintenance difficult.

Another important factor to consider is that we must understand the purpose of minifying a code and how it can be applied to each programming language, because it becomes different due to own language syntax rules and of his its interpreter and/or compiler.

The purpose of the minified style has the following concept:

the aim of the minified style is ensure gains of performance/performance and/or remove unnecessary data/characters to the execution of the code, this data changes according to the language of programming being used - which in fact may include to removal of tabs, comments, spaces, line breaks, etc.

The most plausible and direct alternative to get close to styles minified us batch scripts, will be the use of operators:

& represents E, | represents OU, && represents SUCESSO NA OPERAÇÃO, || represents FALHA NA OPERAÇÃO.

Thus a batch code of N lines can be executed in only 1 line or you will have fewer lines than your original version. Cases where repeat labels need to be used cannot be applied to the minified style.

Below are examples of execution similar to minified style.

You can choose by running cmd.exe with the /c parameter to run the command sequence of the desired script:

cmd /e /v /c "for /l %a in (0,1,10) do (cls & echo %a & echo. & set /p num=Qual numero voce viu? & if %a==!num! (echo Ok. & pause>nul) else (echo Errado.) & pause>nul)"

The same script inside the file. bat can be written from as follows:

@echo off & SetLocal EnableDelayedExpansion & for /l %%a in (0,1,10) do (cls & echo %%a & echo. & set /p num=Qual numero voce viu? & if %%a==!num! (echo Ok. & pause>nul) else (echo Errado.) & pause>nul)

In his original version, applying clean code concepts, and the language pattern is like this:

@ECHO off

SetLocal EnableDelayedExpansion
    
:: Exibição de números de 0 à 10 
:: O usuário deve acertar o número que apareceu.
for /l %%a in (0, 1, 10) do (
   cls
   echo %%a
   echo.
   cls
   set /p num=Qual numero voce viu?
   if %%a==!num! (
      echo Ok.
      pause >nul
   ) else (
      echo Errado.
      pause>nul
   )
)

Exit

Browser other questions tagged

You are not signed in. Login or sign up in order to post.