0
0
Bash Scriptingscripting~15 mins

Making scripts executable (chmod +x) in Bash Scripting - Mini Project: Build & Apply

Choose your learning style9 modes available
Making a Bash Script Executable with chmod +x
📖 Scenario: You have written a simple bash script to greet users. Now, you want to run it directly from the terminal without typing bash before the script name.
🎯 Goal: Make your bash script executable using the chmod +x command and run it directly.
📋 What You'll Learn
Create a bash script file named greet.sh with a greeting message.
Add execute permission to the script using chmod +x greet.sh.
Run the script directly using ./greet.sh.
💡 Why This Matters
🌍 Real World
Making scripts executable is essential to run automation tasks, system maintenance scripts, or any custom commands quickly without typing the interpreter every time.
💼 Career
System administrators, DevOps engineers, and developers often write and run executable scripts to automate workflows and manage servers efficiently.
Progress0 / 4 steps
1
Create the bash script file
Create a file named greet.sh and write the following lines exactly:
#!/bin/bash
echo "Hello, welcome to the bash scripting world!"
Bash Scripting
Need a hint?

The first line #!/bin/bash tells the system this is a bash script.

2
Add execute permission to the script
Use the command chmod +x greet.sh to add execute permission to the greet.sh file.
Bash Scripting
Need a hint?

Use chmod +x followed by the script file name to make it executable.

3
Run the script directly
Run the script directly by typing ./greet.sh in the terminal.
Bash Scripting
Need a hint?

Use ./ before the script name to run it from the current directory.

4
See the output of the script
Write a command to display the output of running ./greet.sh. The output should be:
Hello, welcome to the bash scripting world!
Bash Scripting
Need a hint?

Running ./greet.sh will print the greeting message to the terminal.