Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have one bash script for installing wordpress and want to add also mysql installer to easly can install database

#!/bin/bash

dr=$1
db=$2


zDir="latest.zip"
wpInstall="https://wordpress.org/"$zDir

eval "mkdir -p "$dr" && cd "$dr" && wget "$wpInstall" && unzip "$zDir" && cp -r "$dr"/wordpress/* "$dr" && sudo chmod -R 0777 "$dr" && sudo chmod -R 0777 "$dr"/* && rm -rf "$dr"/wordpress && rm -f -r "$zDir" && echo WordPress installatio$

echo "CREATE DATABASE IF NOT EXISTS `"$db"` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci" | mysql -u root -p

here I have one realy wierd problem:

When I run script like this:

$ ./install-wp.sh /var/www/test project_something

installer install wordpress, place all files on the rigt place but when start part with mysql I get 2 errors.

First is:

> ./install-wp.sh: line 13: project_something: command not found

and second after mysql passowrd is entered:

ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci' at line 1

How to fix this?

share|improve this question
2  
Firstly, double quotes don't nest. Secondly, eval is evil. printf the evaluated string to understand your mistake. – xhienne Dec 17 '16 at 14:47
    
Instead of using && all over the place why not just set -e? – ssdecontrol Dec 17 '16 at 15:16
    
And why do you even need eval here anyway – ssdecontrol Dec 17 '16 at 15:17
    
To be honnest, I'm web developer who trying to learn bash and already made few scripts but I',m baby in this. Don't know all of this things and need help. – Ivijan Stefan Stipić Dec 17 '16 at 15:18
    
@ssdecontrol i find that like solution to run some inline commands. – Ivijan Stefan Stipić Dec 17 '16 at 15:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.