I am trying to compare a variable with a String but I have not found a way to do it, the variable is the result of a function, which the result can be "Terminal" or "Server", which I can print without any problem, the The problem is that I can't find a way to compare it with a string, here is my code:
function seleccionar(){
osascript <<EOT
set rTipo to the button returned of (display dialog "$1" buttons {"Terminal", "Servidor"} default button "Servidor")
if(rTipo = "Terminal")then
return rTipo
do shell script "echo 'type=terminal'> ~/Desktop/type.txt"
end if
if(rTipo = "Servidor")then
return rTipo
do shell script "echo 'type=servidor'> ~/Desktop/type.txt"
end if
EOT
}
value="$(seleccionar 'Selecciona el tipo de instalacion:')"
echo $value
I'm looking to compare it like this:
if value == "Servidor ; then
if lsof -Pi :3306 -sTCP:LISTEN -t >/dev/null ; then #comprueba el puerto 3306
echo "El puerto 3306 ya se encuentra en uso"
exit 1
fi
fi
is there any way?
To supplement your own answer to your question.
In addition to [[ you can use test or [ For example, to compare a string, as you did with
[[ "$value" = "Terminal" ]]
you could do it the same way with:test
and[
are synonymous with bash's own commands. Instead[[
it is an updated version of [ , however it is not portable.For more information about those commands, you can refer to the following links.
https://unix.stackexchange.com/questions/306111/what-is-the-difference-between-the-bash-operators-vs-vs-vs
https://unix.stackexchange.com/questions/306111/what-is-the-difference-between-the-bash-operators-vs-vs-vs
I found the way to do it, here an example: