I was recently starting to setup my usual alias. I ended up needing to pass more information than my alias originally needed

$ alias runserver = 'python manage.py runserver'
$ runserver 80  // turns out you need sudo
$ sudo runserver 80
$ sudo: runserver: command not found

Now as I was writing this i realized maybe the alias isn't set for root. Could that be it?

If not, could someone explain why this doesn't work.

Please and thank you

2 Answers 2


Note: the body of this question is a duplicate of Aliases not available when using sudo.

In the above question, they solved the sudo problem by aliasing sudo too:

alias sudo='sudo '

Note that the title is misleading, "alias with parameter" would be a function. Assuming that your runserver alias would accept a single argument, the port:

runserver(){ python manage.py runserver $1;}

If runserver accepts an unknown amount of parameters, pass all parameters using:

runserver(){ python manage.py runserver "$@";}

For the latter syntax, consult the bash manual.

  • mm, yes, I always forget that hack.
    – geekosaur
    Mar 12, 2011 at 20:48

sudo doesn't see aliases in the invoking shell. Aliases in .bashrc will show up with sudo -s or sudo -i; the former is your .bashrc, the latter for root's.

In any case, wouldn't the easier way be alias runserver='sudo python manage.py runserver'?

  • I dont always want to run it as root.
    – myusuf3
    Mar 13, 2011 at 0:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .