A system administrator is reviewing a Bash script (.sh) designed to monitor a server maintenance task on a Linux workstation. The script must repeatedly check the status of a background process every 30 seconds and continue checking as long as the process state remains active. Which of the following basic scripting constructs should be used to repeatedly execute the status check until the process finishes?
- A while loop constructAnswer
- BA for loop construct
- CAn if...else conditional statement
- DAn environment variable declaration
Answer
A while loop construct is used to repeatedly execute commands as long as a specified condition remains true.
A while loop construct is designed to test a conditional expression and execute a block of code repeatedly as long as that condition evaluates to true. In this scenario, the process status check must run indefinitely at 30-second intervals until the background process completes, making a while loop the correct choice.
Step-by-Step Solution
Key Concept
Scripting Control Constructs (While Loop vs. For Loop vs. Conditional Branching)