Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer
    
mm, yes, I always forget that hack. –  geekosaur Mar 12 '11 at 20:48
add comment

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

share|improve this answer
    
I dont always want to run it as root. –  myusuf3 Mar 13 '11 at 0:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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