Bird
0
0

You want to write a script that runs with Bash but also works if Bash is installed in a different location. Which shebang line is best?

hard🚀 Application Q8 of 15
Bash Scripting - Basics
You want to write a script that runs with Bash but also works if Bash is installed in a different location. Which shebang line is best?
A#!/usr/bin/env bash
B#!/bin/bash
C#!/bin/sh
D#!/usr/local/bin/bash
Step-by-Step Solution
Solution:
  1. Step 1: Understand interpreter location variability

    Bash may be installed in different paths on different systems.
  2. Step 2: Use env to find Bash dynamically

    The line #!/usr/bin/env bash uses the env command to locate Bash in the user's PATH.
  3. Final Answer:

    #!/usr/bin/env bash -> Option A
  4. Quick Check:

    Use env for flexible interpreter path [OK]
Quick Trick: Use #!/usr/bin/env bash for portable scripts [OK]
Common Mistakes:
MISTAKES
  • Hardcoding /bin/bash only
  • Using /bin/sh which may not be Bash
  • Assuming /usr/local/bin/bash always exists

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes