Denys Vlasenko | 77b32cc | 2010-09-06 11:27:32 +0200 | [diff] [blame] | 1 | # Test for correct handling of backslashes. |
| 2 | # Note that some lines in each heredoc start with a tab. |
| 3 | |
| 4 | a=qwerty |
| 5 | |
| 6 | echo Quoted heredoc: |
| 7 | cat <<"EOF1" |
| 8 | a\ |
| 9 | b |
Denys Vlasenko | c3adfac | 2010-09-06 11:46:03 +0200 | [diff] [blame] | 10 | a\\ |
| 11 | b |
Denys Vlasenko | 77b32cc | 2010-09-06 11:27:32 +0200 | [diff] [blame] | 12 | 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- |
| 13 | -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- |
Denys Vlasenko | acd5bc8 | 2010-09-12 15:05:39 +0200 | [diff] [blame] | 14 | 123456 `echo v'-$a-\t-\\-\"-\'-\`-\--\z-\*-\?-'` |
| 15 | 123456 $(echo v'-$a-\t-\\-\"-\'-\`-\--\z-\*-\?-') |
Denys Vlasenko | 77b32cc | 2010-09-06 11:27:32 +0200 | [diff] [blame] | 16 | c\ |
| 17 | EOF1 |
| 18 | echo |
| 19 | |
| 20 | echo Unquoted heredoc: |
| 21 | cat <<EOF2 |
| 22 | a\ |
| 23 | b |
Denys Vlasenko | c3adfac | 2010-09-06 11:46:03 +0200 | [diff] [blame] | 24 | a\\ |
| 25 | b |
Denys Vlasenko | 77b32cc | 2010-09-06 11:27:32 +0200 | [diff] [blame] | 26 | 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- |
| 27 | -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- |
Denys Vlasenko | acd5bc8 | 2010-09-12 15:05:39 +0200 | [diff] [blame] | 28 | 123456 `echo v'-$a-\t-\\-\"-\x-\`-\--\z-\*-\?-'` |
| 29 | 123456 $(echo v'-$a-\t-\\-\"-\x-\`-\--\z-\*-\?-') |
Denys Vlasenko | 77b32cc | 2010-09-06 11:27:32 +0200 | [diff] [blame] | 30 | c\ |
| 31 | EOF2 |
| 32 | EOF2 |
| 33 | echo |
| 34 | |
| 35 | echo Quoted -heredoc: |
| 36 | cat <<-"EOF3" |
| 37 | a\ |
| 38 | b |
Denys Vlasenko | c3adfac | 2010-09-06 11:46:03 +0200 | [diff] [blame] | 39 | a\\ |
| 40 | b |
Denys Vlasenko | 77b32cc | 2010-09-06 11:27:32 +0200 | [diff] [blame] | 41 | 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- |
| 42 | -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- |
Denys Vlasenko | acd5bc8 | 2010-09-12 15:05:39 +0200 | [diff] [blame] | 43 | 123456 `echo v'-$a-\t-\\-\"-\'-\`-\--\z-\*-\?-'` |
| 44 | 123456 $(echo v'-$a-\t-\\-\"-\'-\`-\--\z-\*-\?-') |
Denys Vlasenko | 77b32cc | 2010-09-06 11:27:32 +0200 | [diff] [blame] | 45 | c\ |
| 46 | EOF3 |
| 47 | # In -heredoc case the marker is detected even if it is indented. |
| 48 | echo |
| 49 | |
| 50 | echo Unquoted -heredoc: |
| 51 | cat <<-EOF4 |
| 52 | a\ |
| 53 | b |
Denys Vlasenko | c3adfac | 2010-09-06 11:46:03 +0200 | [diff] [blame] | 54 | a\\ |
| 55 | b |
Denys Vlasenko | 77b32cc | 2010-09-06 11:27:32 +0200 | [diff] [blame] | 56 | 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- |
| 57 | -$a-\t-\\-\"-\'-\`-\--\z-\*-\?- |
Denys Vlasenko | acd5bc8 | 2010-09-12 15:05:39 +0200 | [diff] [blame] | 58 | 123456 `echo v'-$a-\t-\\-\"-\x-\`-\--\z-\*-\?-'` |
| 59 | 123456 $(echo v'-$a-\t-\\-\"-\x-\`-\--\z-\*-\?-') |
Denys Vlasenko | 77b32cc | 2010-09-06 11:27:32 +0200 | [diff] [blame] | 60 | c\ |
| 61 | EOF4 |
| 62 | EOF4 |
| 63 | # The marker is not detected if preceding line ends in backslash. |
| 64 | # TODO: marker should be detected even if it is split by line continuation: |
| 65 | # EOF\ |
| 66 | # 4 |
| 67 | # but currently hush doesn't do it. (Tab before "4" is not allowed, though.) |
| 68 | echo |
| 69 | |
| 70 | echo "Done: $?" |