tampurus

2 If else

Dec 6th, 2021
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.68 KB | None | 0 0
  1. # only if
  2. echo enter a number
  3. read x
  4. if [[ $x -gt 10 ]] #if [[ $x -gt 0] ]
  5. then
  6.   echo number greter then 10
  7. fi
  8.  
  9. # Output
  10. enter a number
  11. 12
  12. number greter then 10
  13.  
  14.  
  15.  
  16. # If with else
  17. echo enter a number
  18. read x
  19. if [[ $x -gt 10 ]] #if [[ $x -gt 0] ]
  20. then
  21.     echo number greter then 10
  22. else
  23.     echo what is physics
  24. fi
  25.  
  26. # Output
  27. enter a number
  28. 5
  29. what is physics
  30.  
  31.  
  32. # with else if
  33. echo enter a number
  34. read x
  35. if [[ $x -lt 0 ]]
  36. then
  37.     echo number is negative
  38. elif [[ $x -gt 0 ]]
  39. then
  40.     echo number is positive
  41. elif [[ $x -eq 0 ]]
  42. then
  43.     echo number is zero
  44. else
  45.     echo you entered something \else
  46. fi
  47.  
  48. # Output
  49. enter a number
  50. -21
  51. number is negative
Advertisement
Add Comment
Please, Sign In to add comment