第一步:生成show.sh脚本
cat /home/gbase/show.sh
#!/bin/bash
#作者:乡村野中医
#创作时间2024-11-21
function show(){
#echo $#
if [ "xdatabases" = x$1 ]
then
echo "select name from sysdatabases;"|dbaccess sysmaster - 2>/dev/null|grep name|sed 's/name/\n/g'
elif [ "xtables" = x$1 ]
then
if [ "x" = "x${database_name}" ]
then
echo '请执行use 库名'
else
#echo "database_name:${database_name}"
echo "select tabname from systables where tabid>99;"|dbaccess $database_name - 2>/dev/null|grep tabname|sed 's/tabname/\n/g'
fi
else
echo '执行命令报错,想查看库请执行show databases'
fi
}
function use(){
if [ x != x$1 ]
then
read -p "gbase>" s t
if [ "xshow tables" != xst ]
then
database_name=$1
#echo "database_name:$database_name"
show tables
fi
else
echo "语法报错,想查看某个库的表请执行 use 库名,show tables"
fi
}
第二步:写入gbasedbt用户的.bash_profile里
su - gbasedbt
echo "source show.sh" >> .bash_profile
第三步:测试命令
1,查看所有库
show databases
2,查看某库的所有业务表
use testdb
>show tables