Skip to main content
Edit: I actually addressed the question.
Source Link

As noted elsewhere in this thread, the original question basically answers itself. Here is an illustration showing that if conditions may also be nested.

This example of usinguses if to check if a file exists and if it is a regular file. If it existsthose conditions are true, then check whether or not it has a size greater than 0.

#!/bin/bash echo "Which error log are you checking today? " read answer if [ -f /opt/logs/$answer*.errors ] then if [ -s /opt/logs/$answer*.errors ] then echo "Content is present in the $answer error log file." else echo "No errors are present in the $answer error log file." fi else echo "$answer does not have an error log at this time." fi 

Here is an example of using if to check if a file exists and if it is a regular file. If it exists, check whether or not it has a size greater than 0.

#!/bin/bash echo "Which error log are you checking today? " read answer if [ -f /opt/logs/$answer*.errors ] then if [ -s /opt/logs/$answer*.errors ] then echo "Content is present in the $answer error log file." else echo "No errors are present in the $answer error log file." fi else echo "$answer does not have an error log at this time." fi 

As noted elsewhere in this thread, the original question basically answers itself. Here is an illustration showing that if conditions may also be nested.

This example uses if to check if a file exists and if it is a regular file. If those conditions are true, then check whether or not it has a size greater than 0.

#!/bin/bash echo "Which error log are you checking today? " read answer if [ -f /opt/logs/$answer*.errors ] then if [ -s /opt/logs/$answer*.errors ] then echo "Content is present in the $answer error log file." else echo "No errors are present in the $answer error log file." fi else echo "$answer does not have an error log at this time." fi 
Source Link

Here is an example of using if to check if a file exists and if it is a regular file. If it exists, check whether or not it has a size greater than 0.

#!/bin/bash echo "Which error log are you checking today? " read answer if [ -f /opt/logs/$answer*.errors ] then if [ -s /opt/logs/$answer*.errors ] then echo "Content is present in the $answer error log file." else echo "No errors are present in the $answer error log file." fi else echo "$answer does not have an error log at this time." fi