I’m working on importing data into MySQL from two business systems. I’ve written some bash scripts to compare the differences between the systems in order to only import the relevant parts. Now I need to construct SQL queries so I can load the data. My main problem is to escape single quotes, I’ve added the code part below that should escape it, but somehow that is only done sometimes, inconsistent. I don’t get it…
TEXT=${PART[1]/\'/\\\'}
So… Are there any better ways / programs I can pipe data through that escapes the data? The absolutely best solution would be to use MySQL’s load data infile mixed with on duplicate update, but if I understand correct, that has not yet been implemented.
Bash is probably not the right tool to do it, but to make your approach at least a bit more correct, you could try
i.e. use double slash to repeat the substitution.
Quoting
man bash: