Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
How to pass parameters to an alias?

I am trying to make a bash alias that will allow me to quickly make an archive of the current git repo.

My current alias is:

alias gitarch="git archive master --format=tar | gzip >$@"

This works great if I supply a destination file exactly like gitarch ~/Desktop/MyArchive.tar.gz but I want to be able to just type a filename and it will always save to the desktop with the tar.gz extension. I tried doing:

alias gitarch="git archive master --format=tar | gzip >~/Desktop/$@.tar.gz"

But it doesnt seem to work correctly.

Can anyone tell me the secret to getting this working?

share|improve this question

marked as duplicate by Gilles, Kevin, Michael Mrozek Jan 14 '12 at 5:50

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

To help a little bit more, if you say alias sayhello='echo "sayhello $@ and something else"' and then you type sayhello Dario it will show sayhello and something else Dario. That is the problem of the $@ you used. You're creating a .tar.gzYOURNAME file, so that the file should be hidden =P – D4RIO Jan 13 '12 at 21:05
up vote 7 down vote accepted

The secret is simply creating a bash function instead - aliases don't support positional parameter substitution:

gitarch() { git archive master --format=tar | gzip >"$1"; }
share|improve this answer
The only "thing" is that it will not be shown when you say just 'alias' – D4RIO Jan 13 '12 at 20:53
@D4RIO No problem, just use set to list the functions or type. – user13742 Jan 13 '12 at 20:54
I would use "$1" instead of $@. – enzotib Jan 13 '12 at 21:26
Thank you, I've managed to get it working with all your help. I'm not exactly sure why this is flagged as duplicate, the other possible question was nothing like mine. – ThisDarkTao Jan 14 '12 at 9:55

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