Don't know what's wrong with my shebang line:
vic@ubuntu:~/Desktop$ ./test.py
: No such file or directory
vic@ubuntu:~/Desktop$ ls -l
...
-rwxr-xr-x 1 vic vic 35 2011-11-06 15:46 test.py
...
vic@ubuntu:~/Desktop$ cat test.py
#!/usr/bin/env python
print('!')
vic@ubuntu:~/Desktop$ /usr/bin/env python
Python 2.7.2+ (default, Oct 4 2011, 20:06:09)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
Any ideas?
vic@ubuntu:~/Desktop$ head -n 2 test.py|hexdump -C
00000000 23 21 2f 75 73 72 2f 62 69 6e 2f 65 6e 76 20 70 |#!/usr/bin/env p|
00000010 79 74 68 6f 6e 0d 0a 0d 0a |ython....|
00000019
vic@ubuntu:~/Desktop$
What is the shebang? The shebang is a special character sequence in a script file that specifies which program should be called to run the script. The shebang is always on the first line of the file, and is composed of the characters #! followed by the path to the interpreter program.
The shebang command must be the first line of the file and can contain any valid path for the interpreter, followed by an argument that the command will receive. The shebang line is read by the system before the execution of the program, but that line will not be automatically deleted.
The shebang line begins with #! , but the rest depends on your operating system. On Windows, the shebang line is #! python3 . On OS X, the shebang line is #! /usr/bin/env python3 .
shebang is used to tell the kernel which interpreter should be used to run the commands present in the file. When we run a file starting with #! , the kernel opens the file and takes the contents written right after the #!
Starting a Script With #! It is called a shebang or a "bang" line. It is nothing but the absolute path to the Bash interpreter. It consists of a number sign and an exclamation point character (#!), followed by the full path to the interpreter such as /bin/bash.
Your file has Windows-type line endings. Convert it to proper Unix-type line endings and you should be good to go.
$ dos2unix test.py
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With