Shell Scripting Tutorial in Hindi | Functions, Arguments & Return Values | Episode 05

Shell Scripting Tutorial for Beginners in Hindi | Episode 05: Functions in Shell Scripting

Welcome to Episode 5 of our Shell Scripting Series!

In this episode, we will learn how to use functions in Bash Shell Scripting to write reusable, organized, and maintainable code. This tutorial includes practical examples using the Ubuntu/WSL terminal.

Functions help us avoid writing the same code repeatedly and make our shell scripts easier to understand and maintain.

📌 What You’ll Learn in This Episode:

✅ What are functions and why do we need them?
✅ How to define and call functions in Bash
✅ Passing arguments to functions
✅ Using `$1`, `$2`, and `$#` inside functions
✅ Return values and exit status in Bash
✅ Capturing function output using command substitution
✅ Local variables using the `local` keyword
✅ Organizing code using a `main` function
✅ Common mistakes when working with functions
✅ Practical project: System Information Script

🛠️ Practical Project: System Information Script

We will build a script using multiple functions to display:

– Current username
– Current working directory
– Disk usage information
– A welcome message

This project will help you understand how to divide a shell script into smaller, reusable functions.

💡 Homework Challenge: Build a Calculator Script

Create a Bash script that performs addition, subtraction, multiplication, and division using separate functions.

Requirements:
– Take two numbers as user input.
– Create separate functions for each arithmetic operation.
– Pass arguments to the functions.
– Handle division by zero.
– Display the result of the selected operation.

🎯 Who Should Watch This Tutorial?

– Beginners learning Linux and Bash scripting
– Developers interested in automation
– Students preparing for Linux and DevOps interviews
– Anyone who wants to write cleaner and reusable shell scripts

📚 Coming Next: Episode 06 — File Handling and Text Processing in Shell Scripting

If you find this tutorial helpful, please LIKE 👍, SHARE 📢, and SUBSCRIBE ❤️ for more programming tutorials.

💬 Comment below and let us know if you completed the calculator challenge!

#ShellScripting #BashScripting #Linux #DevOps #ProgrammingHindi