Skip to content

Instantly share code, notes, and snippets.

@amypellegrini
Last active June 20, 2019 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amypellegrini/7d0efe57e2676907200daeaf6c742524 to your computer and use it in GitHub Desktop.
Save amypellegrini/7d0efe57e2676907200daeaf6c742524 to your computer and use it in GitHub Desktop.
Make file executable in UNIX-style command line

Make file executable in UNIX-style command line

Recently I started to learn Python. My first experiment consisted of a simple script named script.py to print the classic "Hello World!" message. To make the file executable, I added the shebang at the top of the file.

Contents in script.py:

#!/usr/bin/env python3

print('Hello World!')

However, when I try to run the script in the terminal, the script doesn't work.

After some research I find out that I need to flag the file as exectuable in order to enable bash to execute the file.

Bash command to flag the file as executable:

chmod u+x script.py

Now I can happily invoke ./script.py in the command line and see the printed message "Hello World!" in the terminal.

References:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment