Here Document Output Redirection – How to Redirect

here-documentio-redirectionshell

How to redirect the output of below command in shell into logfile.

sqlplus -s "/nolog" <<EOF
conn / as sysdba
@?/sqlpatch/19282021/postinstall.sql
exit;
EOF

Best Answer

Just use redirection operator > at the first line:

sqlplus -s "/nolog" <<EOF >logfile
conn / as sysdba
@?/sqlpatch/19282021/postinstall.sql
exit;
EOF

You can also write >logfile at the beginning of the line, what is equally legal syntax in most shells, but less commonly practiced.

>logfile sqlplus -s "/nolog" <<EOF
conn / as sysdba
@?/sqlpatch/19282021/postinstall.sql
exit;
EOF
Related Question