subshell.sh 752 B

12345678910111213141516171819202122232425262728
  1. #/bin/sh
  2. setopt --verbose
  3. rm -rf shell-test
  4. mkdir shell-test
  5. cd shell-test
  6. # Simple sequence (grouping)
  7. { echo test > testfile }
  8. test "$(cat testfile)" = "test" || echo cannot write to file in subshell && exit 1
  9. # Simple sequence - many commands
  10. { echo test1 > testfile; echo test2 > testfile }
  11. test "$(cat testfile)" = "test2" || echo cannot write to file in subshell 2 && exit 1
  12. # Does it exit with the last exit code?
  13. { test -z "a" }
  14. exitcode=$?
  15. test "$exitcode" -eq 1 || echo exits with $exitcode when it should exit with 1 && exit 1
  16. { test -z "a" || echo test }
  17. exitcode=$?
  18. test "$exitcode" -eq 0 || echo exits with $exitcode when it should exit with 0 && exit 1
  19. cd ..
  20. rm -rf shell-test