vonloxley/sqsh

Regression: Variable expansion does not work inside single quotes

Closed this issue · 2 comments

Hi,

When I used sqsh 2.5.16.1 with Sybase, I could use a \func definition such as:

\func -x \tables
    \if [ $# -ne 1 ]
        \echo "usage: \tables <partial table name>"
        \return 1
    \fi
    select  u.name, substring(o.name, 1, 64)
    from    sysobjects o, sysusers u
    where       o.type = 'U'
            and o.name like '%${1}%'
            and o.uid = u.uid
    order by 2 asc
    go
\done

\tables Data

And it would give me a list of tables having Data in their name, plus the user who owns it.

This does not work anymore, because the ${1} isn't getting expanded to the provided value in the current version. Seems at some time some logic was introduced to NOT expand variables that are enclosed by single quotes?

This basically makes it impossible for me to pass filter conditions to a function...

If you don't have time to look into this, perhaps you can only point me to the correct code location so I can attempt a fix on my own?

Seems to come from this commit: bdec3b8

I've figured it out. I need to "escape" the single quotes using double-back-slashes like:

\func -x \tables
    \if [ $# -ne 1 ]
        \echo "usage: \tables <partial table name>"
        \return 1
    \fi
    select  u.name, substring(o.name, 1, 64)
    from    sysobjects o, sysusers u
    where       o.type = 'U'
            and o.name like \\'%${1}%\\'
            and o.uid = u.uid
    order by 2 asc
    go
\done

Closing the issue.