Which line is used at the start of a Bash script to specify the interpreter?

Study for the OSCP Linux Exam. Use our flashcards and multiple-choice questions to test your skills. Each query comes with detailed hints and explanations to enhance your preparedness. Get ready to conquer the exam!

Multiple Choice

Which line is used at the start of a Bash script to specify the interpreter?

Explanation:
The line at the very top that starts with #! is called a shebang. It tells the operating system which interpreter should execute the rest of the file. For a Bash script, the conventional shebang is #!/bin/bash, which specifies the Bash program located at /bin/bash. When the script has execute permission and is run (for example, ./script), the kernel uses that interpreter to run the script, ensuring Bash syntax and features are understood. Other choices point to different interpreters—Python, sh, or zsh—so they would run the script under those shells, not Bash. In some environments, /bin/bash might not exist; a portable alternative is #!/usr/bin/env bash, but the direct path #!/bin/bash is the canonical way to indicate Bash.

The line at the very top that starts with #! is called a shebang. It tells the operating system which interpreter should execute the rest of the file. For a Bash script, the conventional shebang is #!/bin/bash, which specifies the Bash program located at /bin/bash. When the script has execute permission and is run (for example, ./script), the kernel uses that interpreter to run the script, ensuring Bash syntax and features are understood. Other choices point to different interpreters—Python, sh, or zsh—so they would run the script under those shells, not Bash. In some environments, /bin/bash might not exist; a portable alternative is #!/usr/bin/env bash, but the direct path #!/bin/bash is the canonical way to indicate Bash.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy