Computer scienceSystem administration and DevOpsCommand lineBash syntax

Conditional statements and test checks

Checking if file exists

Report a typo

Check if the file exists or not. If it doesn't exist, print File does not exist. If it does exist, check if it is empty. If it is empty, print File exists but is empty. If it exists and is not empty, print File exists and is not empty.

Note: The absolute path of a file (including its name) is passed to the solve() function as a parameter.

Tip: Check the reading to see which flags are used to check for the presence of a file and to check if it is empty. And don't forget the logical operators! They might be useful here.

Sample Input 1:

/tmp/tolstoy/WarAndPeace.txt

Sample Output 1:

File exists but is empty
Write a program in Shell
#!/usr/bin/env bash

solve() {
# add your solution here

}
___

Create a free account to access the full topic