Home > Net >  CMD to bash script conversion semicolumn
CMD to bash script conversion semicolumn

Time:05-11

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 of VAR.
  • set PATH="${PATH1};${PATH_NAME};" assigns the values of PATH1 and PATH_NAME to variable PATH, 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
  • Related