I am writing a cmd script for creating self signed certificate using keytool. I wanted to check if the alias already present in keystore ,
So I need to execute the below command and store it in a variable. So that if the variable is null I can assume that alias doesnt exists,
keytool -list -v -storepass "%KEYSTORE_PASS%" -keystore cert/seurat-keystore.jks ^| find "Alias name: 1"
I tried with
FOR /F "tokens=* delims=" %%A IN ('keytool -list -v -storepass "%KEYSTORE_PASS%" -keystore cert/seurat-keystore.jks ^| find "Alias name: 1"') DO SET Variable=%%A
echo %Variable%
but it displays echo off. Same I achieved in shell script using the below code,
if [ -n "$(keytool -list -v -storepass "${KEYSTORE_PASS}" -keystore cert/seurat-keystore.jks | grep 'Alias name: 1')" ] ; then
fi
How can I achieve the same in cmd script ? Any help will be really appreciable !!!
Excuse me. You wrote “if the variable is null I can assume that alias doesnt exists”. If the
echo %variable%command show ECHO OFF, then the variable is null! I think your code is correct, but slightly change it this way:Another way is: