1

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

myusuf3
  • 34,189

2 Answers2

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.

Lekensteyn
  • 174,277
0

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'?

geekosaur
  • 11,597