[英]Using bashrc to define an alias with loop in Ubuntu
使用別名很方便,但在這種情況下
alias ssh.1='ssh user@192.168.0.1'
alias ssh.2='ssh user@192.168.0.2'
alias ssh.3='ssh user@192.168.0.3'
我想通過 ssh 連接到范圍 192.169.0.[0-100],
如何使用帶循環的變量來設置它
或者我只是逐行定義它?
您可以使用循環
for i in {1..100}
do
alias ssh.$i="ssh user@192.168.0.$i"
done
您可以將以下函數添加到您的 bashrc :
ssh_range() {
# if your first argument is a number and within the accepted range
if [[ $1 =~ ^[0-9]+$ ]] && (( $1 >= 0 && $1 <= 100 ))
then
ssh "user@192.168.0.$1"
else
return 1
fi
}
然后你就這樣稱呼它: ssh_range 1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.