我正在做一個有點像自動登錄的項目。下面是 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),它將:
問題是,我希望該函數僅在登錄頁面與 URL 匹配時運行https://github.com/login
。因此,如果我想將任何其他網站 URL 設置為默認值,它將不會運行,除非我導航到 github 登錄頁面。然後只有它運行。我試圖解釋的事情就像 .json 文件中的這一行。
"matches": ["https://github.com/login"]
在 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 教程以開始使用。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句