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

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

function gd() {
    gvimdiff $1 dir/$1
  • is there anyway to do it as a single command in a CLI? – kirill_igum Jun 9 '11 at 18:41
  • 4
    That is a single command. – Ignacio Vazquez-Abrams Jun 9 '11 at 18:52
  • so i did "function gd() { gvimdiff $1 dir/$1; }" but when i run it: "gd res.tex", as an output i get contents of "dir" . did i miss something? – kirill_igum Jun 10 '11 at 1:48
  • 'function gd () { gvimdiff $1 dir/$1; }' worked thank you – kirill_igum Jun 11 '11 at 19:49
  • yep, no problem! Glad to help! – Wuffers Jun 12 '11 at 0:08

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.

  • can you suggest a link so i can find out more about this? googling didn't give me much – kirill_igum Jun 9 '11 at 18:39

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.