control-structure-as-command.sh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/bin/sh
  2. source $(dirname "$0")/test-commons.inc
  3. setopt --verbose
  4. rm -rf /tmp/shell-test 2> /dev/null
  5. mkdir -p /tmp/shell-test
  6. pushd /tmp/shell-test
  7. touch a b c
  8. # Can we do logical stuff with control structures?
  9. ls && for $(seq 1) { echo yes > listing }
  10. if not test "$(cat listing)" = "yes" { fail for cannot appear as second part of '&&' }
  11. rm listing
  12. # FIXME: These should work!
  13. # for $(seq 1) { echo yes > listing } && echo HELLO!
  14. # if not test "$(cat listing)" = "yes" { echo for cannot appear as first part of '&&' }
  15. # rm listing
  16. # Can we pipe things into and from control structures?
  17. # ls | if true { cat > listing }
  18. # if not test "$(cat listing)" = "a b c" { fail if cannot be correctly redirected to }
  19. # rm listing
  20. # ls | for $(seq 1) { cat > listing }
  21. # if not test "$(cat listing)" = "a b c" { fail for cannot be correctly redirected to }
  22. # rm listing
  23. for $(seq 4) { echo $it } | cat > listing
  24. if not test "$(cat listing)" = "1 2 3 4" { fail for cannot be correctly redirected from }
  25. rm listing
  26. if true { echo TRUE! } | cat > listing
  27. if not test "$(cat listing)" = "TRUE!" { fail if cannot be correctly redirected from }
  28. rm listing
  29. popd
  30. rm -rf /tmp/shell-test
  31. echo PASS