shell-no-trail-bslash.in 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #! @AM_TEST_RUNNER_SHELL@
  2. # Copyright (C) 2012-2017 Free Software Foundation, Inc.
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2, or (at your option)
  7. # any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. # A "shell" that chokes on '-c' commands and/or shell scripts having
  17. # a trailing '\' character (possibly followed by whitespace only).
  18. # This is to emulate problems seen in older bash versions (e.g., bash
  19. # 2.05b). See also automake bug#10436.
  20. set -u
  21. am_SHELL=${AM_TESTSUITE_SHELL-'@SHELL@'}
  22. (
  23. set -e
  24. shell_command=; unset shell_command
  25. shell_script=; unset shell_script
  26. while test $# -gt 0; do
  27. case $1 in
  28. # The shell might be invoked by make e.g. as "sh -ec" or "sh -ce".
  29. # Be liberal (in the spirit of defensive programming) and accept
  30. # both forms.
  31. -*c*) shell_command=$2; shift;;
  32. -?*) ;;
  33. *) break;;
  34. esac
  35. shift
  36. done
  37. if test x${shell_command+"set"} != x"set"; then
  38. if test $# -gt 0; then
  39. shell_script=$1
  40. shell_command=$(cat <"$shell_script")
  41. else
  42. # Some make implementations, like *BSD's, pass the recipes to the
  43. # shell through its standard input. Trying to run our extra checks
  44. # in this case would be too tricky, so we just skip them.
  45. exit 0
  46. fi
  47. fi
  48. original_shell_command=$shell_command
  49. tab=' '
  50. nl='
  51. '
  52. case "$shell_command" in
  53. *" "|*"$tab"|*"$nl")
  54. shell_command=$(printf '%s\n' "$shell_command" | tr -d " $tab$nl");;
  55. esac
  56. case "$shell_command" in
  57. *\\)
  58. {
  59. printf '%s\n' "$0: recipe/script ends with backslash character"
  60. printf '%s\n' "=== BEGIN recipe/script"
  61. if test x${shell_script+"set"} = x"set"; then
  62. cat <"$shell_script"
  63. else
  64. printf '%s\n' "$original_shell_command"
  65. fi
  66. printf '%s\n' "=== END recipe/script"
  67. } >&2
  68. exit 1
  69. ;;
  70. esac
  71. )
  72. if test $? -gt 0; then
  73. # Some of our scripts or makefile recipes had invalid contents.
  74. exit 3
  75. fi
  76. exec ${AM_TESTSUITE_SHELL-'@SHELL@'} ${1+"$@"}