A user is asking the systems administrator for assistance with writing a script to verify whether a file exists.
Which of the following commands should replace the <CONDITIONAL> string?
Correct Answer: A. if [ -f "$filename" ]; then
The correct syntax to check if a file exists in a shell script is if [ -f "$filename" ]; then. The -f flag tests whether the given path refers to a regular file, and the use of brackets and semicolon (;) is required for proper syntax. This structure ensures the script will conditionally execute a block only if the specified file actually exists and is not a directory.
Why other options are incorrect:
Discover a range of courses designed to provide you with the knowledge and skills needed to excel in your chosen field.
You don’t need one month to study and pass your test.
With Prepsaret, it takes you a few days to grasp all the concepts needed to pass your exams