如何連接/組合某些 bash cli 命令的別名

弄濕

我有以下別名 .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 命令”。

在這種情況下如何組裝和運行命令

卡米爾庫克

不要將命令存儲在變量中。使用函數。

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。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章