J
J
Javasavr2019-06-22 18:51:54
linux
Javasavr, 2019-06-22 18:51:54

How to INSERT into a table with special characters through a bash script?

Hello, I have a problem, I need to INSERT into a MySQL table through a bash script, but I need to INSERT into a table with special characters, all my attempts ended in failure, I searched on stackoverflow, I tried to use it `for a table and columns, I will be grateful for your help in my problem, this is how i tried to use INSERT in my script:

INSERT INTO `ener-data`(`id`, `date`, `v-out-sun`, `a-out-sun`, `v-out-h`, `a-out-h`, `in1`, `in2`, `in3`, `in4`, `in5`) VALUES (null,'$date', и.т.д)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Saboteur, 2019-06-23
@Javasavr

In single quotes, characters can be passed as is.
In double quotes, some retain the special meaning ($, \)
backslash escapes the next one character if it is a special character.
You did not give an example of a line that does not work for you, but in fact it is not difficult there.
You can put it in a separate file, you can do redirection through <

K
ky0, 2019-06-22
@ky0

In order not to suffer with escaping, you can put the query in a separate sql file from the script and feed it to the mysql client.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question