我在unix中尝试以下内容:
count=sqlplus -s ${DB_USER}/${DB_PASS}@${DB_INST} << END
set echo off head off verify off feed off pages 0 lin 120
select COUNT(USERNAME) from v$session where status not in ('INACTIVE') and osuser not in ('oracle');
exit;
END
echo $count
但它正在评估$session
为null并且仅查询表"v"
。以任何方式在unix中查询此表。
答案 0 :(得分:1)
假设您正在使用bash
,如果引用 heredoc 终止字符串(即:<< 'END'
),则会阻止$...
count=sqlplus -s ${DB_USER}/${DB_PASS}@${DB_INST} << 'END'
set echo off head off verify off feed off pages 0 lin 120
select COUNT(USERNAME) from v$session where status not in ('INACTIVE') and osuser not in ('oracle');
exit;
END
echo $count
来自man bash
:
here-documents的格式为:
<<[-]word here-document delimiter
如果单词不加引号,则here-document的所有行都要进行参数扩展,命令替换和算术扩展,忽略字符序列\,并且必须使用\来引用字符\,$和`