Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
share|improve this question

2 Answers 2

up vote 7 down vote accepted

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

function gd() {
    gvimdiff $1 dir/$1
}
share|improve this answer
    
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.

share|improve this answer
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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