将mysql命令的输出解析为bash脚本中的变量 [英] Parse the output of a mysql command into a variable in a bash script

查看:55
本文介绍了将mysql命令的输出解析为bash脚本中的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用bash脚本清理数据库,并且我需要使用users表中最大的ID号,以便在脚本中包含这一行

I'm trying to use a bash script to sanitize a database and I need to use the largest ID Number from the users table so I have this line in my script

MAXID=$(mysql -u root -proot elis27 -e "select max(idnumber) from mdl_user;")
echo $MAXID

在我的脚本中,该行的输出为

And the output of that line in my script is

max(idnumber) 3

如何解析mysql命令的输出,以使MAXID仅为3?

How can I parse the output of the mysql command so that MAXID is just 3?

推荐答案

使用-skip-column-names (或简称为 -N )选项可以省略输出中的列名称标题:

Use the --skip-column-names (or -N for short) option to omit column name headings in the output:

MAXID=$(mysql -u root -proot -N elis27 -e "select max(idnumber) from mdl_user;")

这篇关于将mysql命令的输出解析为bash脚本中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆