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
4

1 回答 1

2

我认为问题在于 sudo 的工作方式。假设您的脚本名为 run_python.sh:

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

然后你可以调用它:

sudo -u runnerdude run_python.sh

或者,如果您坚持,您的脚本可能如下所示:

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

注意将命令连接在一起的单引号和反斜杠。要运行您的脚本:

run_python.sh
于 2012-10-26T18:18:26.593 回答