0

I am trying to assign the output of

select name from v$asm_diskgroup;

to a variable in Shell . The script is failing because of special character '$' in the table name .

Note : While i tried assigning value of " select sysdate from dual" it worked like charm.

Any help would be appreciated.

Query that worked:

count=$(sqlplus -s $configuser/$configpass@$ORACLE_SID <<END
        select sysdate from dual;
        exit;
END
)
echo $count

Query in which I am facing issue:

count=$(sqlplus -s $configuser/$configpass@$ORACLE_SID <<END
        select name from v$asm_diskgroup
        exit;
END
)
echo $count
0

You need to put your string with a $ in single quotes:

value=$(... 'select name from v$asm_diskgroup;')

Otherwise, the shell will try to expand a variable named asm_diskgroup. The shell will not expand variables within single quotes.

  • Facing the error . SP2-0734: unknown command beginning "'select na..." - rest of line ignored. – Siva Aug 11 '15 at 14:23
  • Can you paste what you're trying? – Andy Dalton Aug 11 '15 at 19:27
0

I have found an simple work around for this:

Instead of using

v$asm_diskgroup

I have assigned it to an variable

tab='v$asm_diskgroup'

count=$(sqlplus -s $configuser/$configpass@$ORACLE_SID <<END
    select name from $tab;
    exit;
END 
)
echo $count

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.