我正在做一個有點像自動登錄的專案。下面是 bash 腳本:
DISPLAY=:0.0 xdotool type $WUSER
DISPLAY=:0.0 xdotool key Tab
DISPLAY=:0.0 xdotool type $DECPASS
DISPLAY=:0.0 xdotool key Return
登錄頁面將有一個默認 URL(例如:https : //github.com/login),它將:
- 自動輸入用戶名
- 按tab鍵
- 輸入密碼
- 在 Chromium 啟動時單擊 Enter。
問題是,我希望該函式僅在登錄頁面與 URL 匹配時運行https://github.com/login。因此,如果我想將任何其他網站 URL 設定為默認值,它將不會運行,除非我導航到 github 登錄頁面。然后只有它運行。我試圖解釋的事情就像 .json 檔案中的這一行。
"matches": ["https://github.com/login"]
uj5u.com熱心網友回復:
在 bash 中,if可用于檢查您的 URL 是否有效。由于您沒有發布任何代碼,我假設了很多事情,但它會證明這個想法。
#!/bin/bash
#
url="$1"
if [[ "$url" == "https://github.com/login" ]]
then
echo "The url is valid, proceding..."
# PUT YOUR CODE HERE
else
echo "The url is not valid, stopping the script..."
exit 1
fi
但由于 only"https://github.com/login"是有效的,您根本無法詢問它并在腳本中對其進行硬編碼。
#!/bin/bash
#
url="https://github.com/login"
# rest of the script follows
......
這是 bash 中的基本知識,您應該通讀 bash 教程以開始使用。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/365424.html
