Can you explain the meaning of -le, -ge, and -ne in Bash?

QuestionsQuestions8 SkillsProDec, 15 2025
0242

Hello! I see you're now working with numeric comparisons in your Bash scripts. That's a very useful feature!

You're asking about the meaning of -le, -ge, and -ne. Here's a breakdown:

  • -le (Less than or Equal to): This operator tests if the number on the left side is less than or equal to the number on the right side.

    # Example:
    NUMBER=5
    if [ $NUMBER -le 5 ]; then
      echo "The number is 5 or less." # This will be true
    fi
    
  • -ge (Greater than or Equal to): This operator tests if the number on the left side is greater than or equal to the number on the right side.

    # Example:
    NUMBER=10
    if [ $NUMBER -ge 10 ]; then
      echo "The number is 10 or greater." # This will be true
    fi
    
  • -ne (Not Equal to): This operator tests if the number on the left side is not equal to the number on the right side.

    # Example:
    NUMBER=7
    if [ $NUMBER -ne 10 ]; then
      echo "The number is not 10." # This will be true
    fi
    

These are essential for building robust conditional logic in your Bash scripts, allowing you to compare numeric values accurately.

Great job moving on to numeric comparisons! Experimenting with the numeric.sh script by changing the NUMBER variable and observing the output is an excellent way to solidify your understanding. Let me know if you have more questions as you continue!

0 Comments

no data
Be the first to share your comment!