heredoc

Invalid body indentation level (expecting an indentation level of at least 4)

风流意气都作罢 提交于 2020-12-26 09:38:27
问题 I just upgraded to PHP 7.3 and I'm getting this error: Invalid body indentation level (expecting an indentation level of at least 4) Here is the code: $html = <<<HTML <html> <body> HTML test </body> </html> HTML; 回答1: This is caused by the new flexible Heredoc syntaxes in PHP 7.3. In previous versions of PHP, the closing marker was not allowed to have indentation: $string = <<<EOF Hello EOF; As of PHP 7.3, the closing marker can be indented. In this example, EOF is indented by 4 spaces. The

Invalid body indentation level (expecting an indentation level of at least 4)

前提是你 提交于 2020-12-26 09:36:06
问题 I just upgraded to PHP 7.3 and I'm getting this error: Invalid body indentation level (expecting an indentation level of at least 4) Here is the code: $html = <<<HTML <html> <body> HTML test </body> </html> HTML; 回答1: This is caused by the new flexible Heredoc syntaxes in PHP 7.3. In previous versions of PHP, the closing marker was not allowed to have indentation: $string = <<<EOF Hello EOF; As of PHP 7.3, the closing marker can be indented. In this example, EOF is indented by 4 spaces. The

Problem with heredoc inside case. Bash script [duplicate]

Deadly 提交于 2020-07-22 14:13:26
问题 This question already has answers here : Indenting heredocs with spaces [duplicate] (2 answers) Closed 3 months ago . If in my terminal I write cat <<-EOF hello EOF I get the expected output, hello. Now, In a script I'm writing I have PARAMS="" while (( "$#" )); do case "$1" in -h|--help) cat <<-EOF hello EOF exit 0 ;; --) # end argument parsing shift ... But vscode is highlighting everything after the line cat<<-EOF as if it all was a string, basically ignoring the EOF. And in fact when I

Problem with heredoc inside case. Bash script [duplicate]

拈花ヽ惹草 提交于 2020-07-22 14:13:02
问题 This question already has answers here : Indenting heredocs with spaces [duplicate] (2 answers) Closed 3 months ago . If in my terminal I write cat <<-EOF hello EOF I get the expected output, hello. Now, In a script I'm writing I have PARAMS="" while (( "$#" )); do case "$1" in -h|--help) cat <<-EOF hello EOF exit 0 ;; --) # end argument parsing shift ... But vscode is highlighting everything after the line cat<<-EOF as if it all was a string, basically ignoring the EOF. And in fact when I

类型-字符串:Heredoc语法结构和Nowdoc语法结构

[亡魂溺海] 提交于 2020-03-01 03:07:01
Heredoc和Nowdoc最主要的作用就是输出大量字符串,特别是HTML的字符串,他可以避免你在使用''或""时的转译问题。 他俩的语法规则不是很难,但是挺怪异,据说是继承于 Perl风格的字符串输出技术,反正是和别的PHP代码挺不像的。 Heredoc就像是双引号,他可以输出字符串并且识别里面的$变量,而且里面有'和"可以直接输出不必转译。可以说方便很多,但是其自身的语言要求也很严谨,一定要仔细。 来看看手册对Heredoc的说明: heredoc句法结构: <<< 。在该提示符后面,要定义个标识符,然后是一个新行。接下来是 字符串 本身,最后要用前面定义的标识符作为结束标志。 结束时所引用的标识符 必须 在一行的开始位置, 而且,标识符的命名也要像其它标签一样遵守PHP的规则:只能包含字母、数字和下划线,并且不能用数字和下划线作为开头。 ( 要注意的是结束标识符这行除了 可能 有一个分号( ; )外,绝对不能包括其它字符。这意味着标识符 不能缩进 ,分号的前后也不能有任何空白或tabs。更重要的是结束标识符的前面必须是个被本地操作系统认可的新行标签,比如在UNIX和Mac OS X系统中是 \n ,而结束标识符(可能有个分号)的后面也必须跟个新行标签。 ) 举一个heredoc和""对比的例子: <?phpecho"<h1>我的午餐</h1> <font color=\

Heredoc for nested command in bash

强颜欢笑 提交于 2020-01-24 10:34:05
问题 I need to ssh into a machine and execute a bunch of commands under sudo bash . Here is what I've tried: sshpass -p "vagrant" ssh vagrant@33.33.33.100 "sudo bash -i -c <<EOF echo ls echo EOF" But it throws me 'bash: -c: option requires an argument\n' . How can I fix this? 回答1: You need to remove -c from your command line to make it accept heredoc: sshpass -p "vagrant" ssh vagrant@33.33.33.100 "sudo bash <<EOF echo ls echo EOF" Also you may remove -i (interactive) option too. bash -c expects

Using variables inside a bash heredoc

不羁岁月 提交于 2020-01-15 11:22:08
问题 I'm trying to interpolate variables inside of a bash heredoc: var=$1 sudo tee "/path/to/outfile" > /dev/null << "EOF" Some text that contains my $var EOF This isn't working as I'd expect ( $var is treated literally, not expanded). I need to use sudo tee because creating the file requires sudo. Doing something like: sudo cat > /path/to/outfile <<EOT my text... EOT Doesn't work, because >outfile opens the file in the current shell, which is not using sudo. 回答1: In answer to your first question,

Indenting heredocs with spaces [duplicate]

不问归期 提交于 2020-01-11 17:42:08
问题 This question already has answers here : here-document gives 'unexpected end of file' error (5 answers) Closed 4 months ago . For personal development and projects I work on, we use four spaces instead of tabs. However, I need to use a heredoc, and I can't do so without breaking the indention flow. The only working way to do this I can think of would be this: usage() { cat << ' EOF' | sed -e 's/^ //'; Hello, this is a cool program. This should get unindented. This code should stay indented:

Trailing spaces removed on Python heredoc lines in PyCharm

孤者浪人 提交于 2020-01-03 13:58:44
问题 I'm using Python 2.7 with unittest2 within PyCharm community 3.4.1. I need to match the textual output of a CLI command with the contents of a string for an automated test. The output of this command frequently has trailing spaces at the end of lines; if I add spaces to the ends of the lines in the heredoc that I'm using to store the expected text, they mysteriously get removed in the editor and don't make it to the file. To work around this I have had to split my heredoc and recombine it