creating database via bash with dash in database-name creating database via bash with dash in database-name bash bash

creating database via bash with dash in database-name


Either you quote the backticks or simply use single quotes instead double quotes around the command:

mysql -uuser -ppw -e 'CREATE DATABASE IF NOT EXISTS `db-name` CHARACTER SET utf8 COLLATE utf8_general_ci'

Otherwise the shell would expand the backticks to a command substitution. Check this: http://tldp.org/LDP/abs/html/commandsub.html

Further note that you don't need the echo command. You can use the -e commandline option of mysql


Use with backslahes before backticks:

mysql -uuser -ppw -e 'CREATE DATABASE IF NOT EXISTS \`db-name\` CHARACTER SET utf8 COLLATE utf8_general_ci'