I am trying to convert a CMD script (.bat) into a .sh script on Linux side.
I did not find a proper documentation for instance for the following lines
set PATH="${PATH1}%;${PATH_NAME};"
another_script.bat -create "%LocalDestination%TEST;%LocalDestination%" -e %GenericEnvironementName% -d "%SettingsPath%/Env"
For the first one it is an export but I do not know it is like the if condition?
${PATH1}=${PATH_NAME}
export PATH=$PATH1
for the second one the expression
"%LocalDestination%TEST;%LocalDestination%"
it's like an assignement? why we put the %
at the end?
$LocalDestination$TEST = $LocalDestination
%GenericEnvironementName%
will be $GenericEnvironementName
%SettingsPath%/Env >>> $SettingsPath/Env?
FOR /f "delims=" %%i IN (file.txt) DO
( if defined PATH2 set PATH2=!PATH2!;%%i
if not defined PATH2 set PATH2=%%i
in sh equivalent it will be ?
filename="test.txt" # loop in the file
while IFS= read -r line;
do if [-z "${PATH2}"]; then # if not defined
export $line
else
export $line # I don't know for the instruction set defined=!PATH2!;%%i
fi
done < $filename
for me the first one set PATH2=!PATH2!;%%i it's the same with the second one?
CodePudding user response:
- Variables in dos bat files are delimited with
%
, before AND after. So%VAR%
is replaced by the value ofVAR
. set PATH="${PATH1};${PATH_NAME};"
assigns the values ofPATH1
andPATH_NAME
to variablePATH
, separated by;
.- In Bash you would write:
export PATH="$PATH1;$PATH_NAME"
- Therefore, yes, any variable referencing is bash is done with
$
before the variable name. So%TATA%
becomes$TATA
. - Example:
%SettingsPath%/Env
-->${SettingsPath}/Env