Help us understand the problem. What is going on with this article?

gitのaliasコマンドに引数を渡す方法

More than 5 years have passed since last update.

gitのaliasコマンドに引数を渡す

引数の渡し方をいろいろ調べたのでメモ。
関数を使うやり方の方が分かりやすくて良さそう。

[alias]
        command1 = "!sh -c 'echo $1 $2' -"
        command2 = "!f(){ echo $1 $2;};f"
$ git command2 hoge fuga
hoge fuga

sh -c を使う

command1 = "!sh -c 'echo $1 $2' -"

最後のハイフンは$0を消すためのダミー。
ハイフン無しで'echo $0 $1'とすると、引数ありの時は一つ目が\$0に。無しの時は\$0にshが入る。

関数を使う

command2 = "!f(){ echo $1 $2;};f"

こちらは見ての通り。{の後のスペースを詰めると動かないので注意。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした