主脚本
配置文件
执行结果
主脚本内容
当前支持INT,VARCHAR,DATE,DATETIME数据类型
由于在awk中用常规方法无法转译单引号,所以用了单引号的八进制编码进行转译代替 47 等价于 '
[root@hadoop01 data]# cat create_table.sh
`#!bin_bash`
`table_name=${1}`
`echo "create table ${table_name}(" >table.txt`
`for column in cat table_column.txt`
`do`
`echo ${column} | awk -F ',' '{if ($1=="id"&&$2=="int") {print $1,$2,"not null auto_increment,"} else if ($1!="id"&&$2=="int") {print $1,$2,"default null,"} else if ($2=="date") {print $1,$2,echo "not null default 470000-00-00 47,"} else if ($2=="datetime") {print $1,$2,echo "not null default 470000-00-00 00:00:00 47,"} else {print $1,$2,echo "not null default 47 47,"}}' >> table.txt`
`done`
`echo "primary key (id));" >>table.txt`