0
0
Bash Scriptingscripting~15 mins

Creating a script file (.sh) in Bash Scripting - Try It Yourself

Choose your learning style9 modes available
Creating a Script File (.sh)
📖 Scenario: You want to automate a simple task on your computer by writing a shell script. This script will greet the user with a friendly message.
🎯 Goal: Create a shell script file named greet.sh that prints a greeting message when run.
📋 What You'll Learn
Create a script file named greet.sh
Add the correct shebang line for bash scripts
Write a command inside the script to print Hello, welcome to scripting!
Make sure the script is executable
Run the script to see the greeting message
💡 Why This Matters
🌍 Real World
Shell scripts automate repetitive tasks like backups, system checks, or starting programs.
💼 Career
Knowing how to write and run shell scripts is essential for system administrators, developers, and anyone working with Linux or Unix systems.
Progress0 / 4 steps
1
Create the script file with the shebang line
Create a file named greet.sh and add the first line #!/bin/bash to tell the system this is a bash script.
Bash Scripting
Need a hint?

The first line in a bash script should be #!/bin/bash to specify the interpreter.

2
Add a greeting message command
Add a line below the shebang in greet.sh that uses echo to print Hello, welcome to scripting!.
Bash Scripting
Need a hint?

Use echo "Your message" to print text in bash scripts.

3
Make the script executable
Use the command chmod +x greet.sh to make the script file executable.
Bash Scripting
Need a hint?

Use chmod +x filename to allow running the script as a program.

4
Run the script and see the output
Run the script by typing ./greet.sh in the terminal and print the output.
Bash Scripting
Need a hint?

Run the script with ./greet.sh and it should print the greeting message.