Build Your Own AI Assistant Part 1 - Creating the Assistant
115007 Views
Is the new Raspberry Pi AI Kit better than Google Coral?
103855 Views
Control Arduino with Python using Firmata / PyFirmata
86426 Views
How to Map with LiDAR - using a Raspberry Pi Zero 2W, RPLidar and Rviz
55270 Views
Node-Red Automation, MQTT, NodeMCU & MicroPython
51306 Views
Creating a Supercomputer with a Raspberry Pi 5 Cluster and Docker Swarm!
50568 Views
Installing and Using DeepSeek-R1:1.5 on a Raspberry Pi with Docker
Gamepad & BurgerBot
Level Up your CAD Skills
Operation Pico
Raspberry Pi Home Hub
Hacky Temperature and Humidity Sensor
Using the Raspberry Pi Pico's Built-in Temperature Sensor
0h 24m
Getting Started with SQL
0h 32m
Introduction to the Linux Command Line on Raspberry Pi OS
0h 42m
How to install MicroPython
0h 8m
Wall Drawing Robot Tutorial
0h 22m
BrachioGraph Tutorial
0h 16m
Learn Linux from the basics to advanced topics.
Learn how to use a Raspberry Pi Pico
Learn MicroPython the best language for MicroControllers
Learn Docker, the leading containerization platform. Docker is used to build, ship, and run applications in a consistent and reliable manner, making it a popular choice for DevOps and cloud-native development.
Learn how to build SMARS robots, starting with the 3D Printing the model, Designing SMARS and Programming SMARS
Learn how to build robots, starting with the basics, then move on to learning Python and MicroPython for microcontrollers, finally learn how to make things with Fusion 360.
Learn Python, the most popular programming language in the world. Python is used in many different areas, including Web Development, Data Science, Machine Learning, Robotics and more.
Learn how to create robots in 3D, using Fusion 360 and FreeCAD. The models can be printed out using a 3d printer and then assembled into a physical robot.
Learn how to create Databases in Python, with SQLite3 and Redis.
KevsRobots Learning Platform
56% Percent Complete
By Kevin McAleer, 4 Minutes
Shell scripting allows you to automate tasks on your Raspberry Pi by writing scripts—collections of commands executed in sequence. This lesson introduces you to the basics of shell scripting, including how to create and run simple scripts.
A shell script is a text file containing a sequence of commands that the shell (command interpreter) can execute. Shell scripts can automate repetitive tasks, manage system configurations, and much more.
shell script
echo is a command that prints text to the terminal.
echo
echo "Hello, World!"
This will simply print “Hello, World!” to the terminal.
You can also redirect the text to a file by using the > operator:
>
echo "Hello, World!" > hello.sh
This will create a file named hello.sh that contains the text “Hello, World!”.
hello.sh
How do we know the contents of the file? For that, we can use the cat command.
cat
cat (catalog) is a command that displays the contents of a file:
cat hello.sh
echo and cat only works if you want to add a single line of text, or show the contents of a file. If you want to add multiple lines of text or edit an existing file you can use a text editor like nano.
nano
To create a shell script, you can use the nano text editor. For example, to create a script that prints “Hello, World!”:
Open nano and create a new file:
nano hello.sh
Add the following content to the file:
#!/bin/bash echo "Hello, World!"
Save and exit nano (use Ctrl + O to save and Ctrl + X to exit).
Ctrl + O
Ctrl + X
To run your script, you need to make it executable and then execute it:
Make the script executable:
chmod +x hello.sh
This will give the script permission to run as an executable.
Run the script:
./hello.sh
You should see “Hello, World!” printed in the terminal.
If you prefer using vim as a text editor, you can create a shell script using the following steps:
vim
Open vim and create a new file:
vim hello.sh
Press i to enter insert mode and add the following content to the file:
i
Press Esc to exit insert mode, then type :wq and press Enter to save and exit.
Esc
:wq
Enter
What does Vim stand for Vim stands for Vi IMproved. Explanation Vi: Vim is an enhanced version of the older text editor called vi, which stands for “visual.” Vi was one of the earliest text editors in the Unix operating system and became widely used due to its efficiency and powerful editing capabilities. IMproved: Vim stands for “Vi IMproved” because it includes many enhancements and additional features that were not present in the original vi editor. These improvements include features like syntax highlighting, multi-level undo, support for plugins, and a more extensive command set, making it a much more powerful and flexible tool than the original vi. vim retains compatibility with vi while offering these additional features, which is why it’s often considered a superset of vi. Despite its steep learning curve, Vim is highly regarded for its speed, efficiency, and the extensive control it gives users over text editing.
Vim stands for Vi IMproved.
Vi: Vim is an enhanced version of the older text editor called vi, which stands for “visual.” Vi was one of the earliest text editors in the Unix operating system and became widely used due to its efficiency and powerful editing capabilities.
Vi
vi
IMproved: Vim stands for “Vi IMproved” because it includes many enhancements and additional features that were not present in the original vi editor. These improvements include features like syntax highlighting, multi-level undo, support for plugins, and a more extensive command set, making it a much more powerful and flexible tool than the original vi.
IMproved
vim retains compatibility with vi while offering these additional features, which is why it’s often considered a superset of vi. Despite its steep learning curve, Vim is highly regarded for its speed, efficiency, and the extensive control it gives users over text editing.
In this lesson, you learned what a shell script is and how to create and run a simple shell script. Shell scripting is a powerful tool for automating tasks and managing your Raspberry Pi more efficiently.
< Previous Next >