How to add a database name with a hyphen character using a script in ubuntu

I tried using this code in a script, but it just created what is inside the backtick. In this example, "echo" table-db "" was created in the database. He did not create a folder name with a hyphen in the request

hyph=`ls -l $DBDIR | egrep '^d' | grep '.-.' | awk '{print $9}'`

dbhype=($hyph)


for dbtry in ${!dbhype[*]}
   do            
        mysql -u$dbUser -p$dbPass -e 'CREATE DATABASE IF NOT EXISTS `echo "table-db"` CHARACTER SET utf8 COLLATE utf8_general_ci';

        echo "Database ${dbhype[$dbtry]} created."

done
+4
source share
1 answer

Mysql can contain alphanumeric characters, underscores, and dollar signs in query table names . To be able to use other ansi characters, you must indicate the names on the feedback charts.

`table-db`

bash . bash - . , , - . , backquotes mysql ,

mysql -e 'CREATE DATABASE `table-db`;'

, bash .

mysql -e "CREATE DATABASE \`table-db\`;"

, , :

mysql -e "CREATE DATABASE \`$dbname\`;"

:

mysql -e 'CREATE DATABASE `'$dbname'`;'
+8

All Articles