这会产生输出页面OK
$mystring = "<<<EOT";
Run Code Online (Sandbox Code Playgroud)
用以下产品替换它
解析错误:语法错误,第737行的file.php中的意外$ end
$mystring = <<<EOT
This is some PHP text.
It is completely free
I can use "double quotes"
and 'single quotes',
plus $variables too, which will
be properly converted to their values,
you can even type EOT, as long as it
is not alone on a line, like this:
EOT;
Run Code Online (Sandbox Code Playgroud)
关于是什么导致解析器窒息的任何想法?
我使用的是PHP 4.4.7.
只有一个文件才会发生此行为,所有其他行为都遵循PHP定义的功能.
我试图重述的是在程序行中可能出错的地方,以便PHP解析器在此失败中显示.
约翰
将文件内容更改为: -
<?php
$mystring = <<<WHATEVER
This is some PHP text.
WHATEVER;
?>
Run Code Online (Sandbox Code Playgroud)
结果=
解析错误:语法错误,第5行的file.php中的意外$ end
任何线索
编辑 …
我正在编写控制器方法的代码,我需要用它来发送电子邮件.我正在尝试使用heredoc语法填写电子邮件正文,但是,结尾标记似乎没有被识别.
$this->email = new Email();
$this->email->from = 'Automated Email';
$this->email->to = 'me@myemail.com';
$this->email->subject = 'A new user has registered';
$this->email->body = <<<EOF
Hello, a new user has registered.
EOF;
$this->email->send();
Run Code Online (Sandbox Code Playgroud)
从打开<<< EOF(直到文件末尾)的所有内容都显示为引号.
任何人都可以看到为什么这不起作用?
任何建议表示赞赏
谢谢.
<-- 似乎在网上无法搜索,所以不得不在这里提出问题.
它们的可搜索名称是什么,如何在线添加变量?
我有这样的命令:
sftp user@host <<EOF
put file.txt
exit
EOF
Run Code Online (Sandbox Code Playgroud)
现在我想把它的输出管道输出zenity --progress,但我找不到放置它的地方.
# SFTP doesn't work anymore
sftp user@host | zenity --progress <<EOF
put file.txt
exit
EOF
# Invalid syntax, no end of heredoc
sftp user@host <<EOF
put file.txt
exit
EOF | zenity --progress
# Not picked as part of the command
sftp user@host <<EOF
put file.txt
exit
EOF
| zenity --progress
# Does not help
sftp user@host | zenity --progress <<EOF
put file.txt
exit
EOF\
| zenity --progress
Run Code Online (Sandbox Code Playgroud) 我最近在python中做了相当多的工作,并希望能够使用它的功能而不是shell/bash内置/ shell脚本.
所以对于像这样的shell管道:
echo -e "Line One\nLine Two\nLine Three" | (cat<<-HERE | python
import sys
print 'stdout hi'
for line in sys.stdin.readlines():
print ('stdout hi on line: %s\n' %line)
HERE
) | tee -a tee.out
Run Code Online (Sandbox Code Playgroud)
所有打印的都是"stdout hi"
需要修复什么?
谢谢!
通过我的代码库中的各种代码,我有以下结构.对于我自己和其他人来说,使用heredoc对于理解代码是有好处的,但是通过网络将数据传输到数据库提供了不必要的批量.
use constant FIND_OBJECTS_SQL => <<' END_SQL';
select object_name
,object_type
,0 PAC_REF
,owner
from all_objects
where (object_name like upper(:1)
or object_name = upper(:1))
and object_type not in ('SYNONYM'
,'PACKAGE BODY')
END_SQL
$object_data = $dbh->selectall_arrayref(FIND_OBJECTS_SQL, $object_name);
Run Code Online (Sandbox Code Playgroud)
将"s /\s +// g"搜索和替换运算符应用于赋值的语法是什么.
以下两次尝试不起作用.
use constant FIND_OBJECTS_SQL => s/\s+/ /g <<' END_SQL';
Run Code Online (Sandbox Code Playgroud)
产生
Use of uninitialized value $_ in substitution (s///) at U:\junk.pl line 5.
Argument " END_SQL" isn't numeric in left bitshift (<<) at U:\junk.pl line 5.
Run Code Online (Sandbox Code Playgroud)
和
use constant FIND_OBJECTS_SQL => <<' …Run Code Online (Sandbox Code Playgroud) 我有一个脚本解析服务器列表,寻找一些东西并在情况正确时执行命令.主服务器通过ssh连接到它们,执行EOF语句中的所有命令:
#!/bin/bash
# parsing servers
# defining one local variable $VAR
ssh -T -p 1234 root@"server-ip" "$variable" << 'EOF'
# doing some stuff...
var_result=$(mysql -hhost -uuser '-ppasswort' -Ddatabase -N -e "SELECT something FROM somewhere WHERE value=$VAR;")
EOF
Run Code Online (Sandbox Code Playgroud)
我知道如果我从EOF中删除单引号,变量可以通过,但如果我这样做,mysql语句将无法工作,一切都会中断.
我知道有传递变量的方法,但有";"的东西 选项之间不适用于我(脚本尝试将其作为命令执行)
有任何想法吗?
我正在为一个没有 bash 经验的朋友写一个脚本。该脚本生成备份脚本,生成 crontab 并运行 crontab 以创建 cron 作业。
我想确定这些备份的日期,因此当前脚本(相关内容)是:
cat <<EOF > ~/scheduledBackups/scripts/finalCutScript.bash
mkdir -p ~/scheduledBackups/FinalCut-`date +%a-%b-%d-%Y_%H`
cp -r $BACKUP_DIR/* ~/scheduledBackups/FinalCut-`date +%a-%b-%d-%Y_%H`
EOF
Run Code Online (Sandbox Code Playgroud)
但是,这会finalCutScript.bash与运行“安装程序”脚本时的日期一起生成。
有没有办法把那个 heredoc 准确地放在里面finalCutScript.bash?我想将所有内容都保存在一个脚本中,以便以后可以使用此脚本框架。
预期行为:
我希望将heredoc 传送到其中的文件包含
mkdir -p ~/scheduledBackups/FinalCut-`date +%a-%b-%d-%Y_%H`
cp -r $BACKUP_DIR/* ~/scheduledBackups/FinalCut-`date +%a-%b-%d-%Y_%H`
Run Code Online (Sandbox Code Playgroud)
实际行为
该heredoc生成的文件包含
mkdir -p ~/scheduledBackups/FinalCut-Fri-Aug-05-2016_16
cp -r ~/Documents//* ~/scheduledBackups/FinalCut-Fri-Aug-05-2016_16
Run Code Online (Sandbox Code Playgroud) 我只想使用heredoc作为哈希文字中的值.如果heredoc是最后一个元素,它可以正常工作:
{
foo: 123,
bar: <<-HEREDOC
a longer text
HEREDOC
}
#=> {:foo=>123, :bar=>" a longer text\n"}
Run Code Online (Sandbox Code Playgroud)
我找不到在heredoc 之后添加另一个键值对的方法.或者,更具体地说,我找不到一种方法来插入分隔逗号而不会导致语法错误:
{
foo: 123,
bar: <<-HEREDOC
a longer text
HEREDOC
# <- causes a syntax error because a comma is missing here, but where to put it?
baz: 456
}
Run Code Online (Sandbox Code Playgroud)