I'm trying to create a bash alias alias backlight='__backlight () { echo "$@"; cd ~/Code/MSI-Backlight; sudo nodejs ~/Code/MSI-Backlight/msi-backlight.js "$@"; }', it works fine with no parameters but breaks when I give it one. It works fine outside of an alias. Does anyone know what's wrong?


You should define it as a function and call it with the alias:

function __blacklight() {
  echo "$@";
  cd ~/Code/MSI-Backlight;
  sudo nodejs ~/Code/MSI-Backlight/msi-backlight.js "$@";
alias backlight='__blacklight'
  • 6
    or just define backlight as a function and forget about the alias. – cas Sep 24 '15 at 1:02
  • It works, is there also a way I could make it not actually change direcotires, like using parenthesies in aliases? – Aido Sep 24 '15 at 1:34
  • Ah, I used pushd [dir] and the popd when I was done. – Aido Sep 24 '15 at 2:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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