Vince
Vince

Reputation: 1133

String to function

I have the following Script:

#!/bin/bash

function MySQLQuery()
{
        echo $1
        #mysql -u root -p << EOF
        #$1
        #EOF
}
MySQLQuery "SELECT * FROM kunden;"

But the Output is: SELECT install.sh FROM kunden. It replaces the * to the name of the script. How can I prevent this?

Or are there any better solutions?

Regards, Vince

Upvotes: 0

Views: 56

Answers (2)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200293

You need to prevent globbing. Put the string in single quotes:

MySQLQuery 'SELECT * FROM kunden;'

and double-quote the parameter inside the function.

Upvotes: 0

Chirlo
Chirlo

Reputation: 6132

Besides what @Ansgar suggested,( MySQLQuery 'SELECT * FROM kunden;'), you also need to enclose the $1 parameter in quotes like :

echo "$1".

That should do the trick

Upvotes: 3

Related Questions