Guest User

Untitled

a guest
Oct 20th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. ---------------------------------------------
  2. -- Version with [[ .. ]] instead of [ .. ] --
  3. ---------------------------------------------
  4. -- Either use --
  5. -- [ "$1" .. ] --
  6. -- or --
  7. -- [[ $1 .. ]] --
  8. ---------------------------------------------
  9. #!/bin/bash
  10.  
  11. if [[ $1 = apple ]]
  12. then
  13. echo "Good, I like Apples"
  14. elif [[ $1 = pear ]]
  15. then
  16. echo "Good, I like Pears"
  17. elif [[ $1 = banana ]]
  18. then
  19. echo "Good, I like Bananas"
  20. else
  21. echo "Oh no, I hate Oranges!"
  22. fi
  23.  
  24. ---------------------------------------------
  25. -- Version with case instead of if --
  26. ---------------------------------------------
  27. #!/bin/bash
  28.  
  29. case $1 in
  30. apple)
  31. echo "Good, I like Apples"
  32. ;;
  33. pear)
  34. echo "Good, I like Pears"
  35. ;;
  36. banana)
  37. echo "Good, I like Bananas"
  38. ;;
  39. *)
  40. echo "Oh no, I hate Oranges!"
  41. ;;
  42. esac
Add Comment
Please, Sign In to add comment