Automation, Orchestration, and Scripting
A script contains the line: if [ $disk_usage > 90 ]; then alert; fi. Each time it runs, the alert fires regardless of usage, and a file named 90 appears in the working directory. Which change fixes the comparison?
Show the answer
Correct answerA. Replace > with -gt
Inside [ ], > is a shell redirection that creates the file 90, leaving [ $disk_usage ] as a one-argument test that is true for any non-empty value. The -gt operator performs the integer comparison. Quoting 90 does not stop the redirection.