Bird
0
0

What will be the output of this script?

medium📝 Command Output Q5 of 15
Bash Scripting - Variables
What will be the output of this script?
echo "Process ID: $$"
false
echo "Exit status: $?"
AProcess ID: [some number] Exit status: 1
BProcess ID: 0 Exit status: 0
CProcess ID: [some number] Exit status: 0
DProcess ID: 1 Exit status: 1
Step-by-Step Solution
Solution:
  1. Step 1: Understand $$ and $? usage

    $$ prints the current script's process ID (a number), false command returns exit status 1 (failure), so $? will be 1.
  2. Step 2: Match output with options

    Process ID: [some number] Exit status: 1 correctly shows process ID as a number and exit status as 1.
  3. Final Answer:

    Process ID: [some number]\nExit status: 1 -> Option A
  4. Quick Check:

    $$=PID, $?=last command exit status [OK]
Quick Trick: false command sets $? to 1; $$ shows script PID [OK]
Common Mistakes:
MISTAKES
  • Assuming exit status is 0 after false
  • Confusing $$ with exit status
  • Thinking PID is always 0 or 1

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes