Movatterモバイル変換


[0]ホーム

URL:


It's FOSSLog in
Sign upSign in
Log in Subscribe

Bash Scripting for Beginners

Get acquainted with bash scripting in this course for beginners.
  • Abhishek Prakash
Abhishek Prakash
4 min read
Warp Terminal

Shell is the core part of Linux. It allows you to interact with the Linux kernel by using various commands like cd, ls, cat etc.

Bash is one of the many available shells for Linux. They have mostly common but not identical syntax. Bash is the most popular shell out there and is the default on most Linux distributions.

You open a terminal or SSH session and you have a shell running in it even if you cannot really visualize it.

linux terminal introduction

When you type a command, it is interpreted by the shell. If the command and syntax are correct, it will be executed otherwise you'll see an error.

Why bash scripts when you can just run Linux commands?

You can enter the commands directly in the terminal and they will be executed.

abhishek@itsfoss:~$ echo "hello world"hello world

And the same can be done in a script as well:

abhishek@itsfoss:~$ cat >> script.sh#!/bin/bashecho "hello world"abhishek@itsfoss:~$ bash script.shhello world

Why do you need shell scripts then? Because you don't have to type the same command again and again. You just run the shell script.

Also, if you have complicated logic in your script, typing it all in the terminal won't be a good idea.

For example, if you enter the command below, it will work. But it is not easy to understand and typing it again and again (or even searching for it in the bash history) is a pain.

if [ $(whoami) = 'root' ]; then echo "root"; else echo "not root"; fi

Instead, you can put in a shell script so that it is easier to understand and run it effortlessly:

#!/bin/bashif [ $(whoami) = 'root' ]; thenecho "You are root"elseecho "You are not root"fi

This was still simple. Imagine a complicated script with fifty or a hundred lines!

What will you learn?

There are nine sections in this bash scripting tutorial. You'll learn to:

💡
All these chapters also contain practice exercises.

Who is the target audience?

Anyone who wants to start learning bash shell scripting.

If you are a student with shell scripting as part of your course curriculum, this series is for you.

If you are a regular desktop Linux user, this series will help you understand most shell scripts you come across while exploring various software and fixes. You could also use it to automate some common, repetitive tasks.

Basically, Bash should be on thelearning roadmap of any serious Linux user.

By the end of this Bash Basics series, you should be able to write simple to moderate bash scripts.

All the chapters in the series have sample exercises so you can learn it by doing it.

🗒️
You'll learn bash shell scripting here. While other shells have mostly the same syntax, their behavior still differs at a few points. Bash is the most common and universal shell, so start learning shell scripting with bash.

Prerequisites

🚧
It is desirable that you have basic knowledge of the Linux command line and any programming language.

If you are absolutely new to the Linux command line, I advise you to get the basics right first.

19 Basic But Essential Linux Terminal Tips You Must Know
Learn some small, basic but often ignored things about the terminal. With the small tips, you should be able to use the terminal with slightly more efficiency.
It's FOSSAbhishek Prakash

You should understand how to go to a specific location in the command line. For that, you need to understand how path works in the Linux filesystem works.

Absolute vs Relative Path in Linux: What’s the Difference?
In this essential Linux learning chapter, know about the relative and absolute paths in Linux. What’s the difference between them and which one should you use.
Linux HandbookAbhishek Prakash

Next, this tutorial series gives you the basic of directory navigation and file manipulation.

Getting Started With Linux Terminal
Want to know the basics of the Linux command line? Here’s a tutorial series with a hands-on approach.
It's FOSSAbhishek Prakash

Let's begin!

Let's learn tocreate your hello world bash shell script and run it.

Bash Basics #1: Create and Run Your First Bash Shell Script
Start learning bash scripting with this new series. Create and run your first bash shell script in the first chapter.
It's FOSSAbhishek Prakash
Bash BasicsCourses 🎓
ShareShareShareShareEmailFeedback
About the author
Abhishek Prakash

Abhishek Prakash

Created It's FOSS 13 years ago to share my Linux adventures. Have a Master's degree in Engineering and years of IT industry experience. Huge fan of Agatha Christie detective mysteries 🕵️‍♂️

Featured
AsteroidOS 2.0

8 Years Later, Linux-based AsteroidOS 2.0 is Here to Add New Life to Your Old Smartwatch

against a mixed green backdrop, there is a yellow-colored cardboard box with 6.19 written on it, and the logo for tux, the mascot penguin of linux on its right,

Linux Kernel 6.19 Arrives! You Get Intel, AMD Improvements, and ASUS Armoury Support

Not Kidding! Bash Shell Manual is Part of Epstein Files 🫣

Not Kidding! Bash Shell Manual is Part of Epstein Files 🫣

this green-colored image shows the gnu wildebeest mascot, with the logo for gnu hurd below, hurd written on the right, and progress report written in black below

36 Years in Making, GNU's Very Own Kernel Project Hurd is Anything But Dead

microsoft power toys logo is on the left, on the right there are two people sat on a desk, the one on left (windows) is looking into the work of the person on right (linux)

Windows 11 May Introduce a Linux-like Feature for its Power Users

Latest
FOSS Weekly newsletter

FOSS Weekly #26.08: KDE Plasma 6.6, Mint Release Schedule Change, ASCII Weather, Firefox Tweaking and More Linux Stuff

Download videos

This is Probably the Best Video Downloader App (And it is Free and Open Source)

a screenshot of plasma 6.6 is shown in this featured image, you can see the taskbar at the bottom, and the welcome center app open above

KDE Plasma 6.6 Turns Spectacle Into an OCR Tool and Ships a New Setup Wizard

Become a Better Linux User

With the FOSS Weekly Newsletter, you learn useful Linux tips, discover applications, explore new distros and stay updated with the latest from Linux world
Great! Check your inbox and click the link.
Sorry, something went wrong. Please try again.
❤️

Support Independent Content

We respect your choice to use an ad blocker! It's FOSS is an independent publication that relies on your support.

Consider supporting us to keep quality Linux content free for everyone.

Read next

What LeetCode? I Found This Platform to Practice Linux Troubleshooting Skills

Exploring and Customizing UKUI Desktop in openEuler

Keep openEuler Updated

Setting Up Basic Things After Installing openEuler

Installing openEuler on a Desktop

Become a Better Linux User

With the FOSS Weekly Newsletter, you learn useful Linux tips, discover applications, explore new distros and stay updated with the latest from Linux world

Great! Check your inbox and click the link.
Sorry, something went wrong. Please try again.
itsfoss happy penguin

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to It's FOSS.

Your link has expired.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.


[8]ページ先頭

©2009-2026 Movatter.jp