Search code examples
linuxstringshellvariablesbackticks

Type backtick in shell string variable


Can anyone tell me how I can type a backtick in my shell variable?

I am building a SQL query in a variable. The column name for that query is also a variable and i need to put it between backticks (it has to be a backtick, not a ' or a ").

example:

SQLQUERY="select `${columnname}` from table"

Thanks!


Solution

  • Use single quotes around the parts containing the back-ticks, or escape the back-ticks with a backslash:

    SQLQUERY='select `'"${columnname}"'` from table'
    SQLQUERY="select \`${columnname}\` from table"