- Create a file
hello.sh - Add the shebang line
#!/bin/bashat the top - Print
Hello, DevOps!usingecho - Make it executable and run it
- What happens if you remove the shebang line?
- The script runs after removing shebang line :
./hello.sh- The kernel checks for a shebang to identify the interpreter.If no shebang is found, the script is executed using the current shell.bash hello.sh- The script is explicitly executed by the Bash shell,independent of the presence of a shebang.sh hello.sh- The script is executed using thesh shell,which may differ in behavior from bash
- Create
variables.shwith:- A variable for your
NAME - A variable for your
ROLE(e.g., "DevOps Engineer") - Print:
Hello, I am <NAME> and I am a <ROLE>
- A variable for your
- Try using single quotes vs double quotes — what's the difference?
- Using double quote
" "- Allow variable expansion - Using single quote
' '- Treat every character exactly as written
- Create
greet.shthat:- Asks the user for their name using
read - Asks for their favourite tool
- Prints:
Hello <name>, your favourite tool is <tool>
- Asks the user for their name using
- Create
check_number.shthat:- Takes a number using
read - Prints whether it is positive, negative, or zero
- Takes a number using
- Create
file_check.shthat:- Asks for a filename
- Checks if the file exists using
-f - Prints appropriate message
Create server_check.sh that:
- Stores a service name in a variable (e.g.,
nginx,sshd) - Asks the user: "Do you want to check the status? (y/n)"
- If
y— runssystemctl status <service>and prints whether it's active or not - If
n— prints "Skipped."
- How to write and execute Bash shell scripts using the shebang (
#!/bin/bash),variables,and user input withread. - How variable assignment works in Bash,including accessing variables with
$and understanding single vs double quotes. - How to control script flow using conditional statements (
if,elif,else) and test operators (-f,-gt,-lt). - How to check file existence and numeric conditions inside shell scripts.
- How to suppress command output using redirection (
> /dev/null). - How to use
systemctl is-activeto programmatically check whether a service is running instead of relying on verbose status output.





