1.

Solve : more than one command per line in a batchfile??

Answer»

Anybody know if it is possible to run more than one command in a line in a batchfile (instead of making a :label)

e.g.:

if '%choice%'=='1' echo You typed 1 (and then) copy 1.txt current.txt

?YES. There are TWO ways.

1.

Code: [Select]if "%X%"=="%Y%" (
Commands here
here
here
....
)

2.
In some cases, I don't know when but && can also be used.

Code: [Select]if "%X%"="%Y%" blah && blahWith a batch file, you can have as many lines as you want, you don't have to squeeze everything on one line.Yes, but their example is an IF statement, where all its contents are required to be on 'one line'. Which can be defined by:

IF ... (
commands....
) else (
commands
)Quote from: DeltaSlaya on July 24, 2007, 12:37:42 AM

In some cases, I don't know when but && can also be used.
Code: [Select]if "%X%"="%Y%" blah && blah

I think you mean the single ampersand symbol &. The double ampersand && has a different meaning.

Single AMPERSANDS allow multiple statements on one line

Code: [Select]CLS & echo hello world & pause & del temp.txt
Is the same as

Code: [Select]CLS
echo hello world
pause
del temp.txt

double ampersands allow conditional execution.

If the code to the LEFT of the && is successful, the code to the RIGHT is executed

Code: [Select]tasklist | findstr "Notepad.exe" && echo Notepad is running

The opposite to this is a double pipe symbol ||

If the code to the LEFT of the || is NOT successful, the code to the RIGHT is executed.

Code: [Select]tasklist | findstr "Notepad.exe" || echo Notepad is NOT running
Yea, thats it. A single & not two would be used in your CASE.


Discussion

No Comment Found