shell簡單處理mysql查詢結果

2021-07-25 21:03:45 字數 1311 閱讀 5638

str=("hello"

"world"

"!") #結果: str: 3 #普通的字串陣列

echo

"str: "

$str1=("hello world !") #結果: str1: 1 #普通的字串陣列

echo

"str1: "

$str2=(`echo

"hello world !"`) #結果: str2: 3 #等價於 str

echo

"str2: "

$ function strdeal

()echo

$1echo

$2echo$3}

echo

"-----------first----------------"

strdeal "hello world !"

echo

"-----------second----------------"

strdeal "hello"

"world"

"!"echo

"-----------third----------------"

strdeal $str1

#等價於second

#!/bin/sh

#filename:demo.sh

cityres=""

citycolnum=5

function getcurvalue

() ] ;then

echo

$#獲取目標結果fi}

#獲取city表總行數

function getcityrownum

()/$citycolnum-1]

}cityres=(`mysql -uroot -p123456 world -e

"select * from city"`) #查詢結果以陣列來儲存,等價於上面的str2

curvalue=`getcurvalue $1

$2` #$1為行數 $2為列數

echo

$curvalue

rownum=`getcityrownum` #獲取總行數

echo

$rownum

呼叫示例

sh demo.sh

12

getcityrownum後的記錄數與實際的記錄數並不一致,這是由於city表name 或者district欄位中由於多個字串組成,如:andorra la vella

這樣就會占用3個位置。

shell處理mysql增 刪 改 查

shell是如何操作mysql的?shell操作mysql其實就是通過mysql命令通過引數去執行語句,跟其他程式裡面是一樣的,看看下面這個引數 e,execute name execute command and quit.disables force and history file.因此我們可...

mysql 簡單增刪改查

增刪改查 以sql server 首先要建立乙個資料庫 建立乙個資料庫的語句 create database test建立乙個 create table testtab 建立語句 id int not null primary key,建立乙個int 型別的id 設定為非空 並且設定為主鍵約束 us...

mysql最簡單的檢視 MYSQL之 簡單查詢

單錶查詢語句 檢視所有 select from teacher 檢視特殊的行 select from teacher where tid 2 檢視特殊字段 select tname from teacher 分頁查詢 select from score limit 0,5 limit 起點 個數 表...