0
0
Bash Scriptingscripting~5 mins

First Bash script in Bash Scripting

Choose your learning style9 modes available
Introduction

A Bash script lets you tell your computer to do tasks automatically. It saves time and avoids mistakes when doing the same steps again and again.

You want to open several programs at once without clicking each one.
You need to rename many files with a pattern quickly.
You want to check your computer's disk space regularly.
You want to automate backups of important files.
You want to run a set of commands every time you start your computer.
Syntax
Bash Scripting
#!/bin/bash

echo "Hello, world!"

#!/bin/bash tells the computer this is a Bash script.

echo prints text on the screen.

Examples
This prints a welcome message.
Bash Scripting
#!/bin/bash

echo "Welcome to my script!"
This prints the current date using a command inside the script.
Bash Scripting
#!/bin/bash

# This is a comment

echo "Today is $(date)"
Sample Program

This script prints the classic greeting message to the screen.

Bash Scripting
#!/bin/bash

# Print a greeting message
echo "Hello, world!"
OutputSuccess
Important Notes

Make sure to give your script permission to run by typing chmod +x scriptname.sh.

Run your script by typing ./scriptname.sh in the terminal.

Comments start with # and help explain your code.

Summary

Bash scripts automate tasks by running commands in order.

Start scripts with #!/bin/bash to tell the system to use Bash.

Use echo to show messages on the screen.