1

I wrote a super simple bash script to get me into a python shell with everything set up like I need but it never actually enters the python shell. What am I doing wrong?

sudo su runnerdude
. /home/runnerdude/foo/env/bin/activate
cd /home/runnerdude/foo/bar
python manage.py shell
1
  • Try sh -x script and show the output. Commented Oct 26, 2012 at 18:18

1 Answer 1

2

I think the problem is in the way sudo works. Assume your script is called run_python.sh:

. /home/runnerdude/foo/env/bin/activate
cd /home/runnerdude/foo/bar
python manage.py shell

Then you can invoke it with:

sudo -u runnerdude run_python.sh

Or, if you insist, your script might looks like:

sudo -u runnerdude '. /home/runnerdude/foo/env/bin/activate; \
    cd /home/runnerdude/foo/bar; \
    python manage.py shell'

Note the single quotes and the backslashes to join the commands together. To run your script:

run_python.sh
Sign up to request clarification or add additional context in comments.

1 Comment

pedantically, don't need the line continuation chars inside single quotes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.