Bird
0
0

What will be the output when you run this script named greet.sh?

medium📝 Command Output Q13 of 15
Bash Scripting - Basics
What will be the output when you run this script named greet.sh?
#!/bin/bash
echo "Hello, $USER!"
ASyntax error
BHello, root!
CHello, $USER!
DHello, your-username!
Step-by-Step Solution
Solution:
  1. Step 1: Understand the variable $USER in bash

    $USER is an environment variable that holds the current user's username.
  2. Step 2: Predict the echo output

    The echo command prints "Hello, " followed by the username, so it outputs "Hello, your-username!" where your-username is the actual user.
  3. Final Answer:

    Hello, your-username! -> Option D
  4. Quick Check:

    $USER expands to username = Hello, your-username! [OK]
Quick Trick: Variables like $USER show your username in scripts [OK]
Common Mistakes:
MISTAKES
  • Thinking $USER prints literally
  • Expecting 'root' always
  • Confusing syntax causing errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes