I try to call the Python script from bash in Ubuntu 16. I want the word "start" printed from python.

bash

#!/bin/bash echo "hello world" set -e set -u dir=`"/home/myname/foo.py"` echo directory = $dir 

python

 # !/usr/bin/python3 # -*- coding: utf-8 -*- st = "start" print(st) class Moo(object): def __init__(self): pass def start(self): return "string from FOO.py" 

terminal

 myname@ubuntu:~$ ./new_bash.sh hello world /home/myname/foo.py: строка 3: st: ΠΊΠΎΠΌΠ°Π½Π΄Π° Π½Π΅ Π½Π°ΠΉΠ΄Π΅Π½Π° /home/myname/foo.py: строка 4: ошибка синтаксиса ΠΎΠΊΠΎΠ»ΠΎ Π½Π΅ΠΎΠΆΠΈΠ΄Π°Π½Π½ΠΎΠΉ лСксСмы `st' /home/myname/foo.py: строка 4: `print(st)' 

Why it happens?

    1 answer 1

    as usual, there is a space in shebang , which is not provided with syntax.

    therefore, it is not the /usr/bin/python3 program that is used to interpret the file, but the current shell.

    • there is a space between # and in the question ! (what is really not supported: Exec format error), but a space after ! from the very beginning was resolved. According to your link, left a more comment - jfs