I'm trying to capitalize the first letter of the output from the %COMPUTERNAME% variable. I have tried the below code which doesn't work.
set host=%COMPUTERNAME%
echo %host% | sed 's/^\(.\)/\1\u\2/g/'
The output should be Beast rather than BEAST or beast
I ever often tend to wrap a powershell command for this:
:: Q:\Test\2018\10\12\SO_52769852.cmd
#Echo off
For /f %%A in ('
Powershell -NoP -C "$Env:COMPUTERNAME.Substring(0,1).ToUpper()+$Env:COMPUTERNAME.Substring(1).ToLower()"
') do set host=%%A
Echo:%host%
Instead of using `SEd`, you could probably do it as a single line using the built-in `Find` command.
#For /F "Tokens=2 Delims=:" %%A In ('"Find "" ":%ComputerName:~,1%" 2>&1"') Do #Echo %%A%ComputerName:~1%
The idea uses a 'quirk' with find.exe, which capitalizes the entire filename in its error message, when it cannot locate a file. I expand the %COMPUTERNAME% variable, asking for just its first character, %ComputerName:~,1%,and precede that with a character which is invalid in a Windows filename, in this case :. If we assume a %COMPUTERNAME% value of iab-desktop, the error message, (stdOut, 2>) from Find "" ":i" would be passed to the Do portion as, File not found - :I. This is the English version string, but that shouldn't matter, because we have asked for the second token delimited by the : character, which will be I. I then prepend that result, stored in %%A to the expanded value of %COMPUTERNAME%, this time asking for all characters except for its first, %ComputerName:~1%. The resulting string will be the value of %COMPTERNAME% with the first character capitalized.
try this:
#echo off
setlocal
set "f_leter=%COMPUTERNAME:~0,1%"
set "the_rest=%COMPUTERNAME:~1%"
call :UpCase %f_leter% f
call ::LoCase %the_rest% rest
set result=%f%%rest%
echo %result%
exit /b %errorlevel%
endlocal
::http://www.robvanderwoude.com/battech_convertcase.php
:LoCase
:: Subroutine to convert a variable VALUE to all lower case.
:: The argument for this subroutine is the variable NAME.
setlocal enableDelayedExpansion
set "var=%~1"
FOR %%i IN ("A=a" "B=b" "C=c" "D=d" "E=e" "F=f" "G=g" "H=h" "I=i" "J=j" "K=k" "L=l" "M=m" "N=n" "O=o" "P=p" "Q=q" "R=r" "S=s" "T=t" "U=u" "V=v" "W=w" "X=x" "Y=y" "Z=z") DO (
SET "var=!var:%%~i!"
)
endlocal&(
if "%~2" neq "" (
set "%~2=%var%"
) else (
echo %var%
)
)&GOTO:EOF
:UpCase
setlocal enableDelayedExpansion
set "var=%~1"
:: Subroutine to convert a variable VALUE to all UPPER CASE.
:: The argument for this subroutine is the variable NAME.
FOR %%i IN ("a=A" "b=B" "c=C" "d=D" "e=E" "f=F" "g=G" "h=H" "i=I" "j=J" "k=K" "l=L" "m=M" "n=N" "o=O" "p=P" "q=Q" "r=R" "s=S" "t=T" "u=U" "v=V" "w=W" "x=X" "y=Y" "z=Z") DO (
SET "var=!var:%%~i!"
)
endlocal&(
if "%~2" neq "" (
set "%~2=%var%"
) else (
echo %var%
)
)&GOTO:EOF
Here's the sed answer, although I'd recommend #LotPings powershell answer on Windows. Note that for a typical %computername% the more key point of your question is converting all but the first character to lower-case.
set host=%COMPUTERNAME%
echo %host% | sed -r 's/^(.)(.*)/\U\1\L\2/'
Related
I need to create a cmd script (and somehow I did) that extracts some lines of text from a series of files and puts them in a new txt file.
The source files are like this:
%
!
! AAA
!
! ------------------------ SOME TEXT ABCDEFGHIJKLMN --------------------------
!
! BBB
! ----------------------------------------------------------------------------
! T5 PUNTA ø 6.5/9.5~ $ 63~
! ----------------------------------------------------------------------------
! T12 PUNTA ø 2.5~ $ 39~
! ----------------------------------------------------------------------------
!
! SOME OTHER TEXT
!
! 1] ABC
! 2] DEF
! 3] ...
OTHER LINE 1
OTHER LINE 2
ETC
%
And the lines I need to extract are the ones between two "! ----------------------------------------------------------------------------" so, in this case, T5 PUNTA ø 6.5/9.5~ $ 63~ and T12 PUNTA ø 2.5~ $ 39~.
I was trying some regular expressions with findstr to match a line with ! only after the relevant lines, which indicates the end of the search, until I came up (by pure chance) with an instruction that matches all and only the lines that I need (luck, I guess).
The snippet is this:
#echo off
setlocal enabledelayedexpansion
if exist output.txt ( break > output.txt )
for /r <path> %%g in (<filename>) do (
...
for /f "tokens=* delims= " %%a in (%%g) do (
echo %%a | findstr /r /c:^\!$ >nul
if errorlevel 1 (...)
) else ( echo %%a >> srcoutput.txt
...
)
)
)
Please focus on the instruction echo %%a | findstr /r /c:^\!$ >nul.
This, for a reason I don't know, matches only the lines T5 PUNTA ø 6.5/9.5~ $ 63~ and T12 PUNTA ø 2.5~ $ 39~. Which is exactly what I want, but I don't know why it works!
Can someone help me understand why this simple expression ^\!$ works?
In my (wrong) understanding, it should match only a line with a single ! (which I had escaped, because otherwise it didn't work) at the beginning and at the end.
Thank you in advance
Actually the comand line:
echo %%a | findstr /r /c:^\!$ >nul
just returns lines that contain a $-character.
This is what happens, step by step:
the command line becomes parsed to (assuming %%a holds <expanded text>):
echo <expanded text> | findstr /r /c:\!$ >nul
so the (unquoted) caret (^) disappears as it is the escape character for cmd; since \ has no special meaning, you could just omit the ^ after all;
since delayed expansion is enabled (actually unnecessarily), the !-sign disappears, because there is only one, so the command line becomes:
echo <expanded text> | findstr /r /c:\$ >nul
the \-symbol acts as an escape character (though particularly for findstr!), so the $-sign loses its special meaning in regular expression (/R) mode (namely to anchor a match to the end of a line) and is therefore treated as a literal character;
the left side of the pipe passes on the text <expanded text> (with a trailing SPACE since there is one before the |), and the right side eventually searches for literal $-characters in that text;
You would achieve the exactly same result using the following command line instead:
echo %%a | findstr /C:$ > nul
though I would rather write it as:
echo(%%a| findstr /C:"$" > nul
to avoid the trailing SPACE and to safely echo any text.
For this task I would probably go for another approach (see all the explanatory rem remarks):
#echo off
setlocal EnableExtensions DisableDelayedExpansion
rem // Define constants here:
set "_ROOT=D:\Target\Path" & rem // (path to root directory)
set "_MASK=*.txt" & rem // (name or mask of files to process)
set "_SAVE=D:\Path\To\output.txt" & rem // (location of output file)
rem // Gather line-feed character:
(set ^"_LF=^
%= blank line =%
^")
rem // Gather carriage-return character:
for /F %%C in ('copy /Z "%~f0" nul') do set "_CR=%%C"
rem // Open output file only once and write to it:
> "%_SAVE%" (
rem // Find matching files and loop through them:
for /R "%_ROOT%" %%F in ("%_MASK%") do (
rem // Check for file existence (only necessary when a dedicated name is given):
if exist "%%~F" (
rem // Store path of current file:
set "FILE=%%~F"
rem // Toggle delayed expansion to avoid troubles with `!`:
setlocal EnableDelayedExpansion
rem // Remove remaining quotes (only necessary when a dedicated name is given):
set "FILE=!FILE:"=!
rem /* Do a multi-line search by `findstr`, which only returns the first line;
rem the searched string is:
rem # anchored to the beginning of a line,
rem # an `!`, a space and a `T`, then
rem # some arbitrary text (without line-breaks), then
rem # a line-break, then another `!` and a space, then
rem # a sequence of one or more `-`,
rem # anchored to the end of a line;
rem only the portion before the explicit line-break is then returned: */
findstr /R /C:"^^^! T.*~!_CR!!_LF!^! --*$" "!FILE!"
endlocal
)
)
)
endlocal
exit /B
This does not exactly search for lines between ! --- etc., but it searches for two adjacent lines where the first one begins with ! + SPACE + T and ends with ~, and the second one consists of ! + SPACE + a sequence of one or more -.
If the input file contains Unix-/Linux-style line-breaks rather than DOS-/Windows-style ones, replace !_CR!!_LF! in the findstr search string in the script by !_LF!.
I have decided to post this as a potential method of achieving your intented goal. It uses a different methodology from the currently accepted answer, the idea is to retrieve the ! ----etc. line numbers, then determine if the lines between any two of them have the required content. This means that it isn't looking to match specific content between those lines and should therefore work, whichever characters your strings are formed using.
#Echo Off
SetLocal EnableExtensions
Set "InFile=somefile.ext"
Set "OutFile=someoutfile.ext"
Set "$#="&For /F "Delims=:" %%G In (
'"%__AppDir__%findstr.exe /RNC:"^! --*$" "%InFile%""')Do (
Set /A _2=%%G-2&Call Set "$#= %%G %%$#%%"&Call Set "$2= %%_2%% %%$2%%")
If Not Defined $# Echo No Matches&%__AppDir__%timeout.exe -3&Exit /B
SetLocal EnableDelayedExpansion
For %%G In (%$2%)Do If "!$#: %%G =!"=="%$#%" Set "$2=!$2: %%G =!"
For %%G In (%$2%)Do Set /A _1=%%G+1&Set "$1= !_1! !$1!"
EndLocal&(For %%G In (%$1%)Do For /F "Tokens=1*Delims=]" %%H In (
'%__AppDir__%find.exe /V /N "" "%InFile%"^
^|%__AppDir__%findstr.exe "^\[%%G\]"')Do Echo %%I)>"%OutFile%"
GoTo :EOF
Just change your input file and output file names on lines 3 and 4, as required.
Please note that I'm unble to test this, so it may not work, or could possibly work in the wrong way. Please test it on files with various similar formats, before using it for real!
I'm trying to create a list of all of the files that are dragged and dropped onto a script, separated by semicolons.
set b =
FOR %%a IN (%*) do (
set "b=%b%%%a;"
) > test.tmp
echo b
pause
This is what I have so far, but the script is not displaying the list of files. What am I doing wrong?
To echo the full paths and filename of the files you are to drag/drop, without double quotes:
#echo off
(for %%a in (%*) do (
echo %%~a;
)
)> test.tmp
type test.tmp
pause
To include double quotes and full path:
#echo off
(for %%a in (%*) do (
echo %%a;
)
)> test.tmp
type test.tmp
pause
to echo filename only, without path:
#echo off
(for %%a in (%*) do (
echo %%~nxa;
)
)> test.tmp
type test.tmp
pause
and to echo filename only, excluding path or extension:
#echo off
(for %%a in (%*) do (
echo %%~na;
)
)> test.tmp
type test.tmp
pause
type test.tmp is just to show you the content of the file after written, you can remove it if you do not need it.
I suggest you also read the help for for command:
for /?
Lastly, if you really want to set a variable (though not needed) you need to enabldelayedexpansion or call echo %%b%% by doubling the %
based on this :
sample code in the file F:\printArguments.bat may be like that:
FOR %%a IN (%*) do (
CALL:PrintTheArgument %%a
)
pause
GOTO:EOF
:PrintTheArgument
echo. %~1
GOTO:EOF
You can test it for example like that:
F:\printArguments.bat "edek" "z" "fabryki" "kredek"
#echo off
setlocal enabledelayedexpansion
set "b="
for %%a in (%*) do (
set "b=!b!%%a;"
)
if defined b (
> test.tmp echo(!b:~0,-1!
)
pause
To append to b in the for loop, delayed expansion may be needed.
Use ! instead of % for delayed expansioned varaibles.
To trim the trailing ;, first check if the variable is defined, then
trim the last character by using -1 in !b:~0,-1!, which gets all
characters from position zero to the 2nd last character.
Note: set b = is variable name of b with a space.
View set /? about how to get substrings from strings.
I have a script that extracts lines such as :
THIS_IS_A_LINE:=
THIS_IS_A_LINE2:=
and outputs all of the same kind into another .txt file as:
THIS_IS_A_LINE
THIS_IS_A_LINE2
The script is the following:
set "file=%cd%/Config.mak"
set /a i=0
set "regexp=.*:=$"
setlocal enableDelayedExpansion
IF EXIST Source_List.txt del /F Source_List.txt
for /f "usebackq delims=" %%a in ("%file%") do (
set /a i+=1
call set Feature[!i!]=%%a
)
cd .. && cd ..
rem call echo.!Feature[%i%]!
for /L %%N in (1,1,%i%) do (
echo(!Feature[%%N]!|findstr /R /C:"%regexp%" >nul && (
call echo FOUND
call set /a j+=1
call set Feature_Disabled[%j%]=!Feature[%%N]:~0,-2!
call echo.!Feature_Disabled[%j%]!>>Source_List.txt
) || (
call echo NOT FOUND
)
)
endlocal
I also have another script that extracts lines such as:
THIS_IS_ANOTHER_LINE:=true
THIS_IS_ANOTHER_LINE2:=true
...
and outputs all of the same kind into another .txt file as:
THIS_IS_ANOTHER_LINE
THIS_IS_ANOTHER_LINE2
...
The script is the following:
set "file=%cd%/Config.mak"
set /a i=0
set "regexp=.*:=true$"
setlocal enableDelayedExpansion
IF EXIST Source_List2.txt del /F Source_List2.txt
for /f "usebackq delims=" %%a in ("%file%") do (
set /a i+=1
call set Feature[!i!]=%%a
)
cd .. && cd ..
rem call echo.!Feature[%i%]!
for /L %%N in (1,1,%i%) do (
echo(!Feature[%%N]!|findstr /R /C:"%regexp%" >nul && (
call echo FOUND
call set /a j+=1
call set Feature_Disabled[%j%]=!Feature[%%N]:~0,-6!
call echo.!Feature_Disabled[%j%]!>>Source_List2.txt
) || (
call echo NOT FOUND
)
)
endlocal
Nevertheless, there is a third kind of lines which contain numerical numbers (also some hexadecimal values), such as:
THIS_IS_AN_UNPROCESSED_LINE:=0xA303
THIS_IS_AN_UNPROCESSED_LINE2:=1943
THIS_IS_AN_UNPROCESSED_LINE3:=HELLO_DOOD_CAN_YOU_PARSE_ME?
So I need the way to extract as well those kind of lines into another .txt file such as:
THIS_IS_AN_UNPROCESSED_LINE:=0xA303
THIS_IS_AN_UNPROCESSED_LINE2:=1943
THIS_IS_AN_UNPROCESSED_LINE3:=HELLO_DOOD_CAN_YOU_PARSE_ME?
So basically extract lines which are not of the kind:
THIS_IS_AN_UNPROCESSED_LINE:=
or
THIS_IS_AN_UNPROCESSED_LINE:=true
but keeping both the sides of the line entry.
I know there must be some trick with the regular expression but I just can't find it out.
You have made your code much more complicated than it needs to be. There is no need to create an array of every line in the file.
If there are no other : or = before the first :=, then you can use FINDSTR to print out all lines that contain a string, followed by :=. FOR /F can capture and parse each matching line into the parts before and after :=, and then IF statements can classify the three different types of lines.
I use n> to open all three output files outside the main code block for improved performance, and then I use the &n> syntax to direct each output to the appropriate, already opened file. I use high numbered file handles to avoid problems described at Why doesn't my stderr redirection end after command finishes? And how do I fix it?.
#echo off
setlocal
set "file=Config.mak"
set /a "empty=7, true=8, unprocessed=9"
%empty%>empty.txt %true%>true.txt %unprocessed%>unprocessed.txt (
for /f "delims=:= tokens=1*" %%A in ('findstr /r "^[^:=][^:=]*:=" "%file%"') do (
if "%%B" equ "" (
>&%empty% (echo %%A)
) else if "%%B" equ "true" (
>&%true% (echo %%A)
) else (
>&%unprocessed% (echo %%A:=%%B)
)
)
)
The above will ignore lines that contain : or = before :=, and it will not work properly if the first character after := is : or =. I'm assuming that should not be a problem.
It should be relatively easy to write a very efficient solution using PowerShell, VBScript, or JScript that eliminates the limitations.
You could also use JREPL.BAT - a powerful and efficient regular expression text processing command line utility. JREPL.BAT is pure script (hybrid batch/JScrpt) that runs natively on any Windows machine from XP onward, no 3rd party exe required. And JREPL is much faster than any pure batch solution, especially if the files are large.
Here is one JREPL solution
#echo off
setlocal
set repl=^
$txt=false;^
if ($2=='') stdout.WriteLine($1);^
else if ($2=='true') stderr.WriteLine($1);^
else $txt=$0;
call jrepl "^(.+):=(.*)$" "%repl%" /jmatchq^
/f Config.mak /o unprocessed.txt >empty.txt 2>true.txt
If all you have to do is classify the lines into three different files, without worrying about stripping off the :=true and := parts for the empty and true lines, then there is a very simple pure batch solution using nothing but FINDSTR.
#echo off
set "file=Config.mak"
findstr /r ".:=$" "%file%" >empty.txt
findstr /r ".:=true$" "%file%" >true.txt
findstr /r ".:=" "%file%" | findstr /r /v ":=$ :=true$" >unprocessed.txt
I am working on a batch script to move files from one master directory which has 1000+ files to sub folders, according to the file name, sub folders have to be created and moved accordingly. Below is the scenario/ file name format.
title_or_work_done_by_user_name.xls
From this file name pattern, I have to pick "user_name" and create a folder for that user_name. I found similar code, but not able to break it exactly at the last 'by'.
#ECHO OFF
SETLOCAL
SET "sourcedir=E:\Source"
SET "destdir=E:\Destination"
FOR /f "tokens=2*delims='by_'" %%a IN ('dir /b /a-d "%sourcedir%\*by_*.xls" ') DO (
ECHO %%a
ECHO(MD "%destdir%\%%a" 2>nul
ECHO(MOVE "%sourcedir%\*by_%%a.xls" "%destdir%\%%a\")
pause
GOTO :EOF
Can some one please help me out in extracting 'user_name' by splitting it at the last occurrence of 'by_'.
Thanks in advance :)
The DELIMS option specifies a list of characters, not a string. So your FOR loop will split tokens at ' or _ or b or y. Also, you have no way of knowing what is the number for the last token. Your design is a dead end.
Option 1
Here is a pure batch solution that will do what you want. I use substitution to convert the file name into a pseudo path. It is then easy to pick off the desired name. Delayed expansion is used in order to access the value of a variable within the same loop (code block) that sets it. The only tricky part is toggling delayed expansion on and off as needed so as to preserve any !. A FOR variable containing the ! character will be corrupted if it is expanded while delayed expansion is enabled.
#echo off
setlocal disableDelayedExpansion
for %%F in (*_by_*.jpg) do (
%= Initialize name without extension =%
set "name=%%~nF"
%= Convert "Part1_by_Part2_by_Name" into "Part1\Part2\Name" =%
setlocal enableDelayedExpansion
for %%f in ("!name: - =\!") do (
%= Only execute endlocal on the first iteration =%
if "!!" equ "" endlocal
%= The name might contain a dot, so need name and extension =%
set "name=%%~nxf"
)
set "file=%%F"
setlocal enableDelayedExpansion
%= Hide error message if folder already exists =%
md "!name!" 2>nul
move "!file!" "!name!"
endlocal
)
Option 2
The logic is simpler if a subroutine is used, as it avoids delayed expansion issues. The CALL makes the code less efficient (slower), but that shouldn't be an issue for a task like this.
#echo off
setlocal disableDelayedExpansion
for %%F in (*_by_*.jpg) do call :moveFile "%%F"
exit /b
:moveFile
set "name=%~n1"
for %%F in ("%name:_by_=\%") do set "name=%%~nxF"
md "%name%" 2>nul
move %1 "%name%"
exit /b
Option 3
The simplest solution is to use my JREPL.BAT utility - a hybrid JScript/batch script that performs regex replacement. JREPL is pure script that runs natively on any Windows machine from XP onward.
#echo off
for /f "tokens=1,2 delims=: eol=:" %%A in (
'dir /b /a-d *_by_*.jpg ^| jrepl "^.*_by_(.*)\.jpg" "$&:$1" /i'
) do (
md "%%B" 2>nul
move "%%A" "%%B"
)
#ECHO OFF
SETLOCAL
FOR %%a IN (
title_or_work_done_by_user_name.xls
title_or_work_done_by_digby_hill.xls
title_or_work_done_by_hook_or_by_crook.xls
) DO CALL :process %%a
GOTO :eof
:process
SET "name=%~1"
:: This is the actual processing
ECHO processing "%name%"
SET "name=%name:_by_=.%"
:loop
FOR /f "tokens=1,2,3*delims=." %%p IN ("%name%") DO IF "%%s"=="" (SET "user_name=%%q") ELSE (
SET "name=%%q.%%r.%%s"&GOTO loop
)
ECHO extracted name is "%user_name%"
GOTO :EOF
I've chosen to use the string _by_ as the separator, since there are names that end "by".
Simply replace the string _by_ with a string that won't occur (or has a restricted use) in the filename. I chose . byt perhaps with sme modifications (like removing the extension from the name using %~n : could be used.
The reult is [string.]*required_name.xls
By repeatedly removing the first token using . as a separator, when there is no 4th+token, then the second token would be the required string.
i want to use my %variable% to manage the conditional clauses in a IF.. THEN.. ELSE in a batch file.
Something like the following:
set variable=%%homedrive%% EQU C:
if %variable% (
echo test ok
) else (
echo test fail
)
if i write on a cmd console:
set test=1 equ 1
if %test% echo OK
it works!
i'll use it in a for /f cicle:
this is my pseudo codethis is my pseudo code to correct
(
rem echo "%systemdrive%;;"
echo "%%COMPUTERNAME%% EQU [x];[some parameters1]"
echo "%%USERNAME%% NEQ [y];[some parameters2]"
echo "%%LOGONSERVER%% EQU [z];[some parameters3]"
[..]
) > "%temp%\CSG_fs.tmp"
[..]
for /f "usebackq tokens=1-2* delims=;" %%a in ("%temp%\CSG_fs.tmp") do (
set cond=%%a& set cond=!cond:~1!
set parm=%%b& set parm=!parm:~0,-1!
echo - cicle: "!cond!" --^> "!parm!"
call if !cond! call:CSG_sub_fs !parm!
echo - done
)
goto:eof
:CSG_sub_fs
[..]
goto:eof
--edit--
how can i use the variable !cond! to decide if execute the call to CSG_sub_fs?
call if !cond! call:CSG_sub_fs !parm!
does not work because it returns: "Can not find the batch label specified - IF"
and if i use
if !cond! call:CSG_sub_fs !parm!
it will say: "call:CSG_sub_fs not expected"
Well - there doesn't seem to be a question, so it's not that easy to answer.
You have a problem with
echo "^%COMPUTERNAME^% EQU [x];[some parameters1]"
because ^ does not escape % - % escapes % - use %%COMPUTERNAME%%...
(you should have been able to check this just by TYPEing "%temp%\CSG_fs.tmp"
Next problem is that
for /f "tokens=1-2* delims=; usebackq" %%a in (%temp%\CSG_fs.tmp) do (
may process the file %temp%\CSG_fs.tmp provided %temp%\CSG_fs.tmp contains no spaces, semicolons or commas. If it contains any of these deafult separators, or certain other characters with a special meaning, then you must enclose the filename in double-quotes "%temp%\CSG_fs.tmp"and use the usebackq option.
You've attempted to use usebackq but DELIMS must be the LAST option if it is used. Your code would set ";","","u","s","e","b","a","c","k" and "q" as delimiters.
Beyond that, perhaps if you explain what you intend to achieve, we'd be able to devise the appropriate code.
Try this:
#ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
CLS
REM I'm setting these variables for testing.
REM That isn't ususally a good idea but the SETLOCAL
REM will ensure they are restored on exit
SET computername=[x]
SET logonserver=[z]
(
rem echo "%systemdrive%;;"
echo "%%COMPUTERNAME%% EQU [x];[some parameters1]"
echo "%%USERNAME%% NEQ [y];[some parameters2]"
echo "%%LOGONSERVER%% EQU [z];[some parameters3]"
) > "%temp%\CSG_fs.tmp"
for /f "usebackqtokens=1-2* delims=;" %%a in ("%temp%\CSG_fs.tmp") do (
set cond=%%a& set "cond=IF !cond:~1! CALL :csg_sub_fs "
set parm=%%b& set parm=!parm:~0,-1!
CALL :varcmd "!cond!" "!parm!"
)
GOTO :eof
:varcmd
%~1 %~2
GOTO :eof
:csg_sub_fs
ECHO parameters supplied to csg_sub_fs were: %*
GOTO :eof
I've forced the variablenames to match the conditions you've used in order to trigger the subroutine calls. Change as you need to prove your concept.
And dont worry about imperfect English. I'm sure I wouldn't do as well in your language!