Skip to main content
Typo.
Source Link
agc
  • 8.5k
  • 2
  • 33
  • 53

This is simpler:

{ [ `wc -l < report` -eq 4 ] || exit; } 2>/dev/null 
echo " Proceed further"

Notes:

  • If report exists and is 4 lines long, then wc -l report returns:

     4 report
    

    ...which -eq can't understand. Instead do wc -l < report which outputs an -eq-friendly:

     4
    
  • There's no need to check if the filereport exists, since the < redirection will do that anyway, and returnreturns the same error code.

  • More specific exit codes. If report does not exist, the exit code is 2. If report is 5 lines long, the exit code is 1.

This is simpler:

{ [ `wc -l < report` -eq 4 ] || exit; } 2>/dev/null 
echo " Proceed further"

Notes:

  • If report exists and is 4 lines long, then wc -l report returns:

     4 report
    

    ...which -eq can't understand. Instead do wc -l < report which outputs an -eq-friendly:

     4
    
  • There's no need to check if the file exists, since the redirection will do that anyway, and return the same error code.

This is simpler:

{ [ `wc -l < report` -eq 4 ] || exit; } 2>/dev/null 
echo " Proceed further"

Notes:

  • If report exists and is 4 lines long, then wc -l report returns:

     4 report
    

    ...which -eq can't understand. Instead do wc -l < report which outputs an -eq-friendly:

     4
    
  • There's no need to check if report exists, since the < redirection will do that anyway, and returns the same error code.

  • More specific exit codes. If report does not exist, the exit code is 2. If report is 5 lines long, the exit code is 1.

Revised as per OP clarifications.
Source Link
agc
  • 8.5k
  • 2
  • 33
  • 53

This is simpler:

{ [ `wc -l < report` -eq 4 ] && echo " Proceed|| further";exit; } 2>/dev/null 
echo " Proceed further"

Notes:

  • If report exists and is 4 lines long, then wc -l report returns:

     4 report
    

    ...which -eq can't understand. Instead do wc -l < report which outputs an -eq-friendly:

     4
    
  • There's no need to check if the file exists, since the redirection will do that anyway, and return the same error code.

This is simpler:

{ [ `wc -l < report` -eq 4 ] && echo " Proceed further"; } 2>/dev/null

Notes:

  • If report exists and is 4 lines long, then wc -l report returns:

     4 report
    

    ...which -eq can't understand. Instead do wc -l < report which outputs an -eq-friendly:

     4
    
  • There's no need to check if the file exists, since the redirection will do that anyway, and return the same error code.

This is simpler:

{ [ `wc -l < report` -eq 4 ] || exit; } 2>/dev/null 
echo " Proceed further"

Notes:

  • If report exists and is 4 lines long, then wc -l report returns:

     4 report
    

    ...which -eq can't understand. Instead do wc -l < report which outputs an -eq-friendly:

     4
    
  • There's no need to check if the file exists, since the redirection will do that anyway, and return the same error code.

Improved text.
Source Link
agc
  • 8.5k
  • 2
  • 33
  • 53

This would return more specific error codes, and is simpler:

{ [ `wc -l < report` -eq 4 ] && echo " Proceed further"; } 2>/dev/null

Notes:

  • If report exists and is 4 lines long, then wc -l report returns:

     4 report
    

    ...which -eq can't understand. Instead do wc -l < report which outputs an -eq-friendly:

     4
    
  • There's no need to check if the file exists, since the redirection will do that anyway, and return the same error code.

This would return more specific error codes, and is simpler:

{ [ `wc -l < report` -eq 4 ] && echo " Proceed further"; } 2>/dev/null

This is simpler:

{ [ `wc -l < report` -eq 4 ] && echo " Proceed further"; } 2>/dev/null

Notes:

  • If report exists and is 4 lines long, then wc -l report returns:

     4 report
    

    ...which -eq can't understand. Instead do wc -l < report which outputs an -eq-friendly:

     4
    
  • There's no need to check if the file exists, since the redirection will do that anyway, and return the same error code.

Source Link
agc
  • 8.5k
  • 2
  • 33
  • 53
Loading