Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to expand variable within single quotes and would give output within single quotes using bash

I would like to expand one variable in bash and would like to get result within single quotes itself.

for example , my script below includes:

    sqlplus -s user/password
    select sys_context
    Where schemaname = '$USERNAME'

I would like to expand it as:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

   Where schemaname = 'XYZ_OWNER'

I tried something like :

   where schemaname = "'""$USERNAME""'"

But it is throwing me below error:

   where schemaname = "'"XYZ_OWNER""'"

Please suggest how can this be resolved.

>Solution :

To get parameter expansion without wordsplitting, double quotes are used. Example:

USERNAME=fluffy
where_clause="where schemaname = '$USERNAME'"

This sets the variable where_clause to the value where schemaname = 'fluffy'.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading