if.sh 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/sh
  2. setopt --verbose
  3. if test 1 -eq 1 {
  4. # Are comments ok?
  5. # Basic 'if' structure, empty block.
  6. if true {
  7. } else {
  8. echo "if true runs false branch"
  9. exit 2
  10. }
  11. if false {
  12. echo "if false runs true branch"
  13. exit 2
  14. } else {
  15. }
  16. # Basic 'if' structure, without 'else'
  17. if false {
  18. echo "Fail: 'if false' runs the branch"
  19. exit 2
  20. }
  21. # Extended 'cond' form.
  22. if false {
  23. echo "Fail: 'if false' with 'else if' runs first branch"
  24. exit 2
  25. } else if true {
  26. } else {
  27. echo "Fail: 'if false' with 'else if' runs last branch"
  28. exit 2
  29. }
  30. # FIXME: Some form of 'not' would be nice
  31. # &&/|| in condition
  32. if true || false {
  33. } else {
  34. echo "Fail: 'if true || false' runs false branch"
  35. exit 2
  36. }
  37. if true && false {
  38. echo "Fail: 'if true && false' runs true branch"
  39. exit 2
  40. }
  41. } else {
  42. echo "Fail: 'if test 1 -eq 1' runs false branch"
  43. exit 1
  44. }