How Do You Troubleshoot a Bash Script with the Error “No such file or directory”?

Problem scenario
An "if" statement in Bash is throwing an error message "No such file or directory." What do you do?

Possible solution #1
Replace the parentheses around the arithmetical comparison with double parentheses. Instead of this:

if ( $numlines < 5); then

Use this:

if (( $numlines < 5)); then

Possible solution #2
Replace the "[]" with "(())".

Instead of this:

if [ $numlines < 5]; then

Use this:

if (( $numlines < 5)); then

Leave a comment

Your email address will not be published. Required fields are marked *