I want to run a command such as this in a bash script:
freebcp <authentication and other parameters> -t "," -r "\r\n"
When run directly on the command line, the command works as expected. But when placed in a variable in a bash script it returns an error such as this:
Msg 20104, Level 3
Unexpected EOF encountered in bcp datafile
Msg 20074, Level 11
Attempt to bulk copy an oversized row to the server
bcp copy in failed
When command is placed in a variable and double quotes are escaped:
cmd="freebcp ${db_name}.dbo.${table_name} in ${p_file} -S ${server_name} -U ${username} -P ${password} -t \",\" -r \"\r\n\" -c"
`$cmd`
Note: Putting the following in the script works as expected:
`freebcp ${db_name}.dbo.${table_name} in ${p_file} -S ${server_name} -U ${username} -P ${password} -t "," -r "\r\n" -c`
So I know there's some quoting/escaping/expansion problems but I can't figure out how to fix it.
Note 2: Single quoting -t -r parameters doesn't work either