0

This is not the complete code, 2 first lines are only for "debug" purpose, I'm new on bash scripting and I don't know why if ls $ACTUAL/${BACKUP_DIR}/${NOMBRE}_*.tgz | wc -l returns 2 ,the script execute the then clause...

COPIAS=$(ls $ACTUAL/${BACKUP_DIR}/${NOMBRE}_*.tgz | wc -l)
echo ${COPIAS}
if [ $(ls $ACTUAL/${BACKUP_DIR}/${NOMBRE}_*.tgz | wc -l)>5 ]
    then
        echo "more than 5"
    else
        echo "5 or less"
fi 
3
  • 1
    Dont parse the output from ls. Commented Mar 7, 2015 at 15:52
  • 1
    Take a look at shellcheck.net Commented Mar 7, 2015 at 15:53
  • related serverfault.com/questions/477503/… Commented Mar 7, 2015 at 15:55

2 Answers 2

2

[ is a normal command, so > is treated as a redirection. You can use [[ (which is a keyword) instead. Alternatively, you can escape > to \> so it isn't treated as a redirection.

Beware that > is for string comparison. To compare two numbers you would use -gt.

Sign up to request clarification or add additional context in comments.

Comments

1
 array=("$ACTUAL/${BACKUP_DIR}/${NOMBRE}_"*.tgz)

 if [[ ${#array[@]} -gt 5 ]]  # -gt: arithmetic operator greater-than
 then
   echo "more than 5"
 else
   echo "5 or less"
 fi

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.