Comparing Batch Files and Shell Scripts

First line @echo off #!/bin/bash
Echo on @echo on #!/bin/bash -x
Comments rem #
Printing to the screen echo echo
Setting a variable set var=value var=value
Getting the value of a variable %var% $var
Name of script %0 $0
Command-line arguments %1 to %9 $1 to $9
Shifting command-line arguments shift (%0 affected) shift ($0 not affected)
Number of command-line arguments n/a $#
If statement if condition command
if [ condition ]
then
	command(s)
fi
If...Else statement
if condition goto truelabel
command(s) if condition is false
goto skiptrue

:truelabel
command(s) if condition true

:skiptrue
if [ condition ]
then
	command(s) if true
else
	command(s) if false
fi
If...ElseIf...Else statement
if condition1 goto truelabel1
if condition2 goto truelabel2
command(s) if no conditions are true
goto skiptrue

:truelabel1
command(s) if condition1 is true
goto skiptrue

:truelabel2
command(s) if condition2 is true

:skiptrue
if [ condition1 ]
then
	command(s) if condition1 is true
elif [ condition2 ]
then
	command(s) if condition2 is true
else
	command(s) if false
fi
Comparing strings (if condition) "s1"=="s2" "s1" == "s2"
Comparing numbers (if condition) "n1"=="n2" (same as strings) n1 -eq n2
Checking if a file exists (if condition) exist file -f file
Checking if a directory exists (if condition) exist directory\nul -d directory
Checking error level (if condition) not errorlevel 0 $? -ne 0
Loop
:loop
command(s)
if condition goto endloop
command(s)
goto loop
:endloop
while [ condition ]
do
	command(s)
done
Infinite loop
:loop
command(s)
goto loop
while [ true ]
do
	command(s)
done
For loop for %%f ( list ) command using %%f
for f in list
do
	command(s) using $f
done
End script
goto end

:end
rem  last line in file
exit