Student
Student

Reputation: 57

error script_name.sh: line 13: [[0: command not found

Good morning ! trying to execute this code but i have an error on if statement . error message : error script_name.sh: line 6: [[0: command not found the problèm is on "if" statement. help please

#!/bin/ksh
jour=$(date +%Y%m%d)
#Control if run is ok or not before sending mail
dir_resultFailure=/transfertCLINK/Share/RESULT_UAT/$jour/FichierFailure/
dir_resultFilteredOut=/transfertCLINK/Share/RESULT_UAT/$jour/FichierFilteredOut/
if [[ `ls $dir_resultFailure | wc -l` -eq 0 ]] &&  [[`ls $dir_resultFilteredOut | wc -l` -eq 0 ]]
then
        echo "repo is empty."
fi

Upvotes: 1

Views: 810

Answers (1)

RavinderSingh13
RavinderSingh13

Reputation: 133528

You could have it in following way.

#!/bin/ksh
jour=$(date +%Y%m%d)
#Control if run is ok or not before sending mail
dir_resultFailure="/transfertCLINK/Share/RESULT_UAT/$jour/FichierFailure/"
dir_resultFilteredOut="/transfertCLINK/Share/RESULT_UAT/$jour/FichierFilteredOut/"
if [[ $(ls $dir_resultFailure | wc -l) -eq 0 ]] &&  [[ $(ls $dir_resultFilteredOut | wc -l) -eq 0 ]]
then
        echo "repo is empty."
fi

Improvments/Fixes in OP's attempts:

  1. Always wrap your variables values inside ".
  2. Using backticks is deprecated now, use $(....) for saving variables values.
  3. Your if condition was not correct, you should have spaces in between [[ and (.

Upvotes: 3

Related Questions