Shell Scripting
setlocal ENABLEEXTENSIONS / ENABLEDELAYEDEX
Another title might be: "dereferencing with CMD"
setlocal ENABLEEXTENSIONS / ENABLEDELAYEDEXPANSION prevents an environment variable that's set in a called script from returning to the caller.
Ie/
Script1.cmd
@echo off
set RET=%1
set %RET%="My return value"
Executed from the command prompt:
Script1.cmd MyVariable
set MyVariablereturns
"My return value"
Adding:
setlocal ENABLEEXTENSIONS
setlocal ENABLEDELAYEDEXPANSIONcauses this behavior to fail.
Diff all combinations of a file in a given
@echo on
setlocal ENABLEEXTENSIONS
setlocal ENABLEDELAYEDEXPANSION
set /A ocount=0
set ARGS=%*
if NOT DEFINED ARGS goto HELP
for /F %%i in ('locate %ARGS%') do (
set /A icount=0
for /F %%j in ('locate %ARGS%') do (
if /I "%%i" NEQ "%%j" if !icount! GEQ !ocount! if EXIST %%i if EXIST %%j bc2 %%i %%j
set /A icount=!icount!+1
)
set /A ocount=!ocount!+1
)
goto end
:HELP
echo compare [options from locate] file
echo Ex/ compare -p . -lw sal.h
echo.
:end
Delete duplicate files
@echo off
REM Enabling shell extensions.
setlocal ENABLEEXTENSIONS
setlocal ENABLEDELAYEDEXPANSION
set arg1=
set arg2=
set CWD=
:shiftargs
if ""%1""== """" goto NextQuestion
if NOT DEFINED arg1 set arg1=%~s1
shift
if NOT DEFINED arg2 set arg2=%~s1
goto shiftargs
:NextQuestion
REM Check to make sure the two directories exist in the filesystem.
if NOT DEFINED arg1 goto CantExecuteQuestion2
if NOT DEFINED arg2 goto CantExecuteQuestion2
if NOT EXIST %arg1% goto CantExecuteQuestion2
if NOT EXIST %arg2% goto CantExecuteQuestion2
REM Gets the current working directory


