how to properly use $1 in an alias with two arguments

i have to compare a number of files and I don't want to change the command in two places all the time. so i want to create an alias in bash.

alias gd='gvimdiff $1 dir/$1'

so that i can get

gvimdiff res.tex dir/res.tex

just by typing

gd res.tex

Solution 1:

You cannot use aliases this way, however, you can define a function do to the same thing.

function gd() {
    gvimdiff $1 dir/$1
}

Solution 2:

Aliases don't work that way. You should be able to use history substitution (e.g. !!:1), (no, bash doesn't allow that) or define a function instead.

Solution 3:

It is very simple tried it in kde neon, ubuntu, manjaro, arch all bash

alias gd="gvimdiff '$1' dir/'$1'"

just add the following commas it will work.