blob: 501af54903c828b722cec4ddfd8e80ebebeb26b1 [file] [log] [blame]
Denys Vlasenko77b32cc2010-09-06 11:27:32 +02001# Test for correct handling of backslashes.
2# Note that some lines in each heredoc start with a tab.
3
4a=qwerty
5
6echo Quoted heredoc:
7cat <<"EOF1"
8a\
9 b
Denys Vlasenkoc3adfac2010-09-06 11:46:03 +020010a\\
11 b
Denys Vlasenko77b32cc2010-09-06 11:27:32 +020012 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
13 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
Denys Vlasenkoacd5bc82010-09-12 15:05:39 +020014 123456 `echo v'-$a-\t-\\-\"-\'-\`-\--\z-\*-\?-'`
15 123456 $(echo v'-$a-\t-\\-\"-\'-\`-\--\z-\*-\?-')
Denys Vlasenko77b32cc2010-09-06 11:27:32 +020016c\
17EOF1
18echo
19
20echo Unquoted heredoc:
21cat <<EOF2
22a\
23 b
Denys Vlasenkoc3adfac2010-09-06 11:46:03 +020024a\\
25 b
Denys Vlasenko77b32cc2010-09-06 11:27:32 +020026 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
27 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
Denys Vlasenkoacd5bc82010-09-12 15:05:39 +020028 123456 `echo v'-$a-\t-\\-\"-\x-\`-\--\z-\*-\?-'`
29 123456 $(echo v'-$a-\t-\\-\"-\x-\`-\--\z-\*-\?-')
Denys Vlasenko77b32cc2010-09-06 11:27:32 +020030c\
31EOF2
32EOF2
33echo
34
35echo Quoted -heredoc:
36cat <<-"EOF3"
37a\
38 b
Denys Vlasenkoc3adfac2010-09-06 11:46:03 +020039a\\
40 b
Denys Vlasenko77b32cc2010-09-06 11:27:32 +020041 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
42 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
Denys Vlasenkoacd5bc82010-09-12 15:05:39 +020043 123456 `echo v'-$a-\t-\\-\"-\'-\`-\--\z-\*-\?-'`
44 123456 $(echo v'-$a-\t-\\-\"-\'-\`-\--\z-\*-\?-')
Denys Vlasenko77b32cc2010-09-06 11:27:32 +020045c\
46 EOF3
47# In -heredoc case the marker is detected even if it is indented.
48echo
49
50echo Unquoted -heredoc:
51cat <<-EOF4
52a\
53 b
Denys Vlasenkoc3adfac2010-09-06 11:46:03 +020054a\\
55 b
Denys Vlasenko77b32cc2010-09-06 11:27:32 +020056 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
57 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
Denys Vlasenkoacd5bc82010-09-12 15:05:39 +020058 123456 `echo v'-$a-\t-\\-\"-\x-\`-\--\z-\*-\?-'`
59 123456 $(echo v'-$a-\t-\\-\"-\x-\`-\--\z-\*-\?-')
Denys Vlasenko77b32cc2010-09-06 11:27:32 +020060c\
61EOF4
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.)
68echo
69
70echo "Done: $?"