把SQL查询结果赋给shell变量
最近在看《基于Linux的Oracle数据库管理》这本书,根据书上的示例写的shell脚本,
#!/bin/bash
VALUE=`sqlplus -silent /nolog < conn scott/tiger set pagesize 0 feedback off verify off heading off echo off numwidth 4 select count( * ) coun from all_objects; exit; END` if [ "$VALUE" -gt 0 ] then echo "The number of rows is $VALUE." exit 0 else echo "There is no row in the table." fi 在执行时总报错误: ./sqlshell.sh: line 9: [: ####: integer expression expected 书上写的应该没错,查找原因,看了一上我机器上的查询结果是:40620 应该是显示的位宽不够,所以"$VALUE"值变成了一个错误的值。 把numwidth 4 改成为 numwidth 5 就能正确执行了。
- 上一篇:Ftp批量上传下载的Shell脚本
- 下一篇:BASH命令提示符改造