0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

bash で引数付きのエイリアスを作成したい!

0
Last updated at Posted at 2021-06-04

メモです。自分の使っているサブネットが 192.168.1.0/24 だったとします。ここで 192.168.1.52 や 192.168.1.103 に ssh したい!そういうエイリアスを作成したい!

そう思ったことはありませんか?そんな時は .bashrc にこんな風に書くと良いそうです。

.bashrc
function s() {
    command ssh root@192.168.1.$1
}

上記を読み込むと以下のように例えば s 52 と実行した際に ssh root@192.168.1.52 と実行されます。

$ s 52
root@192.168.1.52's password:

.bash_alias にこう書くのはダメなようです。echo してみるとわかりますが ssh root@192.158.1. 52 と $1 の前にスペースが入ってしまうようです。

alias s='ssh root@192.168.1.$1'

詳細は参照から。

参照: bashで引数つきのエイリアスを設定する

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?