Barry Margolin wrote:
> In article <
648ad4ea-4770-48b6...@googlegroups.com>,
> James <
hsle...@yahoo.com> wrote:
>
>> To feed query into mysql, below syntax fails if query contains some
>> characters such as (*,',",$,etc.). How do I escape $query?
>>
>> printf "$query" | mysql -h <host> -u <user> -A <db> -p <pw>
>
> Why are you using printf if you're not doing formatting? Just use echo:
>
> echo "$query" | mysql ...
Different versions of echo behave differently if arguments contain
backslashes, or if the first argument is -n, -e or -E. So echo
should only be used to output fixed strings which are known not
to contain backslashes and are not -n, -e or -E.
James was right to use printf to print his "$query" string; he just
left out the format-string argument that should have preceded it:
printf '%s\n' "$query" | mysql ...
--
Geoff Clare <
net...@gclare.org.uk>