set -e?#!/bin/bash set -e echo "Start" false echo "End"
What will be printed when this script runs?
#!/bin/bash set -e echo "Start" false echo "End"
set -e stops the script if a command fails.The set -e option causes the script to exit immediately if any command returns a non-zero status. The command false returns failure, so the script stops after printing "Start" and does not print "End".
set -x do in this script?#!/bin/bash set -x VAR=5 echo $((VAR + 3))
What will be the output?
#!/bin/bash set -x VAR=5 echo $((VAR + 3))
set -x shows each command before running it.The set -x option prints each command with a plus sign before executing it. So the script prints the commands VAR=5 and echo 8 before printing the result 8.
set -e or set -o errexit causes the script to exit on any error. Option A uses set -e and will stop after false. Option A uses set -o errexit but the echo says it will print, which is incorrect.
set -e?#!/bin/bash echo "Start" ls /nonexistent_directory echo "End"
What will be the output?
#!/bin/bash echo "Start" ls /nonexistent_directory echo "End"
set -e, script continues after errors.Without set -e, the script prints "Start", then the error message from ls, then continues to print "End".
set -x and stop on error with set -e?set -ex enables both set -e (stop on error) and set -x (print commands). This helps debug and stops the script on failure.