You are maintaining a script that updates system packages and restarts a critical service afterward, but only if the update succeeds. Which line of code correctly implements this behavior?
The use of && ensures that the subsequent command (service httpd restart) is executed only if the preceding command (yum update -y) completes successfully with an exit status of 0. Using ; does not check the success of the previous command. Using || only executes the subsequent command if the preceding one fails. Using & will put the first command in the background and immediately run the second one regardless of the first one's result.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What does the '&&' operator do in shell scripting?
Open an interactive chat with Bash
What is the significance of exit statuses in shell commands?
Open an interactive chat with Bash
What are some common commands used to manage services in Linux?