Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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'm wondering if it is possible to define an alias with parameters.

For example, when I have to compile a tex file I execute pdflatex and then I have to open the pdf:

$ pdlatex Main.tex
$ Open Main.pdf

Is there a way for defining an alias like this:

alias buildPdf="pdflatex x.tex && Open x.pdf"

Where x is a parameter?

share|improve this question

migrated from stackoverflow.com Dec 24 '11 at 5:22

This question came from our site for professional and enthusiast programmers.

marked as duplicate by Gilles, Stéphane Gimenez, Ulrich Dangel, Renan, jasonwryan Aug 18 '12 at 20:38

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.

up vote 7 down vote accepted

You can use a function. Add to your .bashrc or simply copypasta into your terminal:

function buildPdf() {
  pdflatex "$1.tex" && Open "$1.pdf"
share|improve this answer
$1 instead of %1, perhaps? – Shawn Chin Dec 23 '11 at 13:50
Thanks, can I define it in the .bashrc? – lucaghera Dec 23 '11 at 13:52
@lucaghera, yes, or in .profile, depending on which file is sourced when you start your shell. – Jan Dec 23 '11 at 13:53
@Jan it returns me this error when I open the bash: -bash: /Users/luca/.profile: line 35: syntax error: unexpected end of file – lucaghera Dec 23 '11 at 13:54
@lucaghera, try adding newlines, as in the updated answer. – Jan Dec 23 '11 at 13:56

With bash this is not possible. Consider using a bash script instead:

pdflatex "$1".tex
Open "$1".pdf
  • Call this 'buildPdf'
  • give it executable permission (chmod +x)
  • place it in a directory listed in $PATH


share|improve this answer

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