我有以下別名 .bash_aliases
ssh51ro="ssh -p12345 [email protected]"
ssh52ro="ssh -p12345 [email protected]"
ssh53ro="ssh -p12345 [email protected]"
...
ssh59ro="ssh -p12345 [email protected]"
我想知道是否可以在 for 回圈中向多個收件人發送相同的命令。我通常會增加一個“i”變數并將別名的名稱連接在一起。
for i in $( seq 1 9 ) ; do ssh5${i}ro date; done
但這似乎不起作用。它特別指出“未找到ssh5 i ro 命令”。
在這種情況下如何組裝和運行命令
uj5u.com熱心網友回復:
不要將命令存盤在變數中。使用函式。
myssh() { ssh -p12345 root@"$@"; }
ssh51ro() { myssh 192.168.15.71 "$@"; }
ssh52ro() { myssh 192.168.8.25 "$@"; }
...
for i in $( seq 1 9 ) ; do ssh5${i}ro date; done
# maybe you want dynamic list of functions based on naming pattern:
for func in $(compgen -A function | grep ssh5.ro); do "$func" date; done
您可能想研究 Ansible 和 Puppet Bolt。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/370914.html
上一篇:計算字串中出現的數字字母
下一篇:如何將字串轉換為僅幾天?
