簡體   English   中英

如何在shell腳本中轉​​義mariadb密碼的特殊字符

[英]how to escape special characters of mariadb password in shell script

我要寫什么shell腳本來登錄mariadb。 Shell腳本在ini文件中讀取了一個包含特殊字符(空白,!@)的密碼。

操作系統是Ubuntu 18.04

ini文件如下:

user=xxx-xxx-xxx
password=xxx /xxx /xx/ !\@

shell腳本如下:

#!/bin/bash
baseDir="$(cd "$(dirname "$0")" && pwd)"
iniPath="$baseDir/backup.ini"
echo "iniPath is $iniPath"

dbUser="$(grep 'user' $iniPath | cut -d '=' -f 2)"
echo "user is $dbUser"

dbPassword="$(grep 'password' $iniPath | cut -d '=' -f 2)"
echo "password is $dbPassword"

mysql -h localhost -u $dbUser -p'$dbPassword' 

如果我按如下所示輸入命令:mysql -h localhost -u xxxxxx -p'xxx / xxx / xx /!@',它將成功記錄日志。 但是,如果我執行shell腳本,它總是導致拒絕用戶訪問。

有什么建議嗎? 謝謝。

您是否嘗試過使用:mysql -h localhost -u $ dbUser -p'echo echo $dbPassword '? (特殊字符`在美國像esc鍵左上角的鍵盤一樣,看起來像后撇號)看起來像帶有密碼的變量在運行之前沒有正確地“打印”到mysql命令中。 我建議嘗試的其他方法是使用-p“ $ dbPassword”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM