bash - How to check if a variable has "mysqli" or "mariadb" value -
i have following piece of script:
set ${db_type:='mysqli'} echo $db_type if [ $db_type -eq "mysqli" -o $db_type -eq "mariadb" ]; #do stuff else echo >&2 "this database type not supported" echo >&2 "did forget -e db_type='mysqli' ^or^ -e db_type='mariadb' ?" exit 1 fi
but piece of script somehow fails on:
if [ $db_type -eq "mysqli" -o $db_type -eq "mariadb" ];
so how can compare if $db_type id either "mysqli" or "mariadb"?
it useful know how fails there few things wrong following:
if [ $db_type -eq "mysqli" -o $db_type -eq "mariadb" ];
- variables unquoted (dangerous within
[
) -eq
comparing integers,=
should used strings (see this question detailed discussion of difference)
as you've tagged bash should aware of improved [[
allows write this:
if [[ $db_type = mysqli || $db_type = mariadb ]];
within [[
don't need quote variables , can use ||
logical or.
you might consider using this:
case $db_type in mysqli|mariadb) # 1 thing ;; *) # other stuff ;; esac
Comments
Post a Comment