(CHEAT SHEET) Programming On The Raspberry Pi

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Circuit Basics

Raspberry Pi, Arduino, and DIY Electronics Tutorials

Raspberry Pi Programming Cheat Sheet


How to write and execute Shell Scripts, C programs, and Python programs:

Shell Scripts
1. Create a file with a ".sh" extension by entering this at the command prompt:
sudo nano example.sh
2. Add the shebang to the first line of the script file:
#!/bin/sh
3. Write and save the script, then make it executable by entering this at the command prompt:
sudo chmod +x example.sh
4. To run the shell script, navigate to the directory where you saved the script file and enter this:
sh hello-world.sh
or
./hello-world.sh

Python Programs
1. Create a file with a ".py" extension by entering this at the command prompt:
sudo nano example.py
2. After writing your program, you can run it by navigating to the directory where the file is saved, then entering this:
python example.py
3. To make the program executable, enter this at the command prompt:
chmod +x example.py
4. Now you can run the program by entering this:
./example.py

C Programs
1. Create a new file with a “.c” extension by entering this at the command prompt:
sudo nano example.c
2. Write your code, save the file, and exit Nano.
3. Compile the source file into a new file with this command:
gcc example.c -o compiledexample
4. Make the compiled file executable by entering this at the command prompt:
chmod +x compiledexample
5. Run the program by entering this:
./compiledexample

You might also like