Search code examples
bashenvironment-variableslatex

Aliased command in bashrc does not correctly use $OLDPWD


I have an alias in bashrc that I use to generate a particular LaTeX document (the main command used is pdflatex) but I want to be able to execute it regardless of where I am. Unfortunately, it seems like you can't use use this command with an absolute path unless the path is 'under' your current directory, so I cd into the directory my .tex file is, run pdflatex, then try to cd back to my previous directory. In bashrc, I have my command as

alias nbr="cd ~/path/to/dir && pdflatex file.tex && cd $OLDPWD"

The command works fine outside of putting me back in my previous directory. For some reason, this command works perfectly fine in a regular bash shell, so I'm guessing there's some issue with what $OLDPWD is considered in the context of bashrc but I'm not sure. Any ideas?


Solution

  • @Cyrus's answer fixed it...should've used single quotes.