Skip to content

T3chnocr4t/Linux

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 

Repository files navigation

Bash Scripting 💻


In this article, we'll explore Bash scripting together, where I'll share what I've learned. While I'm not an expert, I can help guide you through everything you need to know about Bash scripting by sharing my insights.

Introdution:

Bash scripting refers to the process of writing scripts using the Bash (Bourne Again Shell) programming language, which is the default command-line interpreter in most Unix-like operating systems, including Linux 🐧 and macOS.

Bash scripting helps users automate tasks, create workflows, and control system resources using commands. It lets users run commands, change files, manage processes, and handle system administration tasks using a powerful scripting language.

Why Use Bash Scripting 😎?

  1. Automation: Saves time by automating repetitive tasks.
  2. Customization: Tailors computing environment to specific needs.
  3. Task Automation: Automates file management, data processing, and more.
  4. System Administration: Manages users, monitors systems, and schedules backups.
  5. Cross-Platform Compatibility: Runs on Linux, macOS, and BSD systems.
  6. Integration: Works well with other languages and tools for complex workflows.
  7. Learning and Education: Helps develop programming,cybersecurity and problem-solving skills.

Essential Components and Concepts in Shell Scripting:

  1. Text Editor: Choose a text editor to write your script. Common options include Vim, Emacs, Nano, Visual Studio Code, Sublime Text.
  2. Shebang: It's the first line of a script that tells the computer which interpreter to use.
  3. File Extension: Scripts often end with .sh, but it's not always necessary.
  4. Permissions: Scripts need permission to run. You make them executable using the chmod +x command.
  5. Arguments: You can give a script information to work with when you run it.
  6. Variables: They're containers that store information in a script.
  7. If Statements: They help the script make decisions based on certain conditions.

Understanding these basics will help you start writing simple scripts to automate tasks on your computer.

A simple Scripts:

Below are some simple scripts that will help you understand the concepts of Bash scripting:

  • So, I started by choosing a text editor. In my case, I choose "nano" and named the file "hello" with the file extension for scripting, which is ".sh"

Screenshot_2024-01-28_04-33-05 (2)

  • Next: I started the script with the shebang 👉(#!/bin/bash) and I also used #, which is known as a comment. Comments are often used to explain what the script/code does, so another person can read and understand it easily.

Screenshot_2024-01-28_04-35-00 (2)

  • To run the script, first, I give the user permission to execute the file. Then, I run the script with './' followed by the file name, or I can type 'bash' followed by the file name. This ensures that the script runs smoothly. Finally, it executes and echoes the desired word.

Screenshot_2024-01-28_04-36-54 (2)

Variable:

  • So, the next script is about variables. In scripting, a variable acts as a storage unit that holds information or data. It allows you to store and modify values that your script can use throughout its execution.

Screenshot_2024-01-28_04-39-21 (2)

You can observe that the script echoes the variable, i.e., the variable name and age, out there.

Screenshot_2024-01-28_04-40-06 (2)

Thanks

That's just the beginning for us! Join me at my GitHub profile, where we'll delve into other scripts and explain what we'll be learning, such as if statements, while loops, and much more. Together, we'll create some useful scripts that we can leverage in the future 😃.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published