Day-03: Creating a Basic Shell Script for User Greetings!

Pakeeza SaeedPakeeza Saeed
1 min read

✨ What Does the Script Do?

This shell script accepts a single argument for a greeting message (e.g., "Hello", "Hi", etc.), then prompts the user to enter their name and finally prints a welcome message using both the provided argument and the user’s name.

📜 The Script

#!/bin/bash

# Check if exactly one argument is provided
if [ $# -ne 1 ]; then
        echo "Usage: $0 <greetings>"
        exit 1
fi

# Save the first argument as a greeting variable
greetings=$1

# Ask for the user's name using read with -p for inline prompt
read -p "Enter your name here: " name

# Print a welcome message
echo "$greetings, $name! Welcome to the group."
0
Subscribe to my newsletter

Read articles from Pakeeza Saeed directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Pakeeza Saeed
Pakeeza Saeed