1

I am reading O'Reilly Learning Python (4th edition). There is a paragraph called Unix Executable Scripts (#!) (page 46).

The example given is the following:

`Use your text editor again to create a file of Python code called brian:

#!/usr/local/bin/python
print('The Bright Side ' + 'of Life...')

` Like in the example, I save this script in a file named 'brian' (no .py, as it is not required).

I then give the file the privileges chmod +x brian

It is then said that I can 'run it from the operating system shell as though it were a binary program:

% brian
The Bright Side of Life...

'

However, when I try from my command window to call "brian", I get the following error:

bash: brian: command not found

But python brian gives me the correct result.

Why calling 'brian' like in the example doesn't work for me?

1 Answer 1

8

You need to do ./brian. Unix will then look for it in the current directory. Your current directory may not be in the system path and hence it is unable to find a command named brian.

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

2 Comments

trying ./brian I got bash: ./brian: /usr/local/bin/python: bad interpreter: No such file or directory I then looked into python in /usr/local/bin ,there is no python, but python3.3. I then replaced #!/usr/local/bin/python by #!/usr/local/bin/python3.3 and it worked
Cool. Nice to hear! I think Learning Python is written with 2.7 in mind, so they have that example there. Feel free to accept the answer if it helped you out. :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.