简体   繁体   English

在cat文件的输出中打印单词echo

[英]Printing the word echo in the output of cat file

I am trying to generate a file using cat in bash where inside the bash, i already ran a script, that i saved into a variable then will be used inside the cat. 我试图在bash中使用cat生成一个文件,在bash中,我已经运行了一个脚本,我保存到变量中然后将在cat中使用。 To ran the script and save the output to a variable, I used the following: 要运行脚本并将输出保存到变量,我使用了以下内容:

declare RESULT=$(./script.pl 5 5 5)

Next, I show an excerpt of the cat file where the variable RESULT is being used. 接下来,我将显示正在使用变量RESULT的cat文件的摘录。

  cat> input.in<<EOF 
  bla bla
  echo $RESULT 
  EOF

What I obtain after running the bash, is the correct output of the variable RESULT. 运行bash后得到的是变量RESULT的正确输出。 However, there is a word echo in the beginning of the file (as shown below). 但是, 文件的开头有一个单词echo (如下所示)。 This is problematic because I am trying to automate a code, and adding the word echo ruins the code. 这是有问题的,因为我正在尝试自动化代码,并添加单词echo会破坏代码。

echo K_POINTS crystal    
     64
     0.00000000  0.00000000  0.00000000  1.562500e-02 
     0.00000000  0.00000000  0.25000000  1.562500e-02 
     0.00000000  0.00000000  0.50000000  1.562500e-02

Can you tell me please what is the problem? 请问你能告诉我什么问题? Thanks a lot! 非常感谢!

Here documents don't run the contents as commands, they just expand values like $RESULT . 这里的文档不会将内容作为命令运行,它们只会扩展$RESULT等值。

cat> input.in<<EOF 
bla bla
$RESULT 
EOF

If you wanted to actually get the output of a command, you can use $(mycommand myarg) but obviously this is pointless for echo 如果你想实际获得一个命令的输出,你可以使用$(mycommand myarg)但显然这对于echo来说毫无意义

Maybe I'm not reading this correctly (apologies if so), but it looks like you are expecting the heredoc to be run as a script. 也许我没有正确地读这个(如果是这样道歉),但看起来你期望heredoc作为脚本运行。 It is not. 它不是。 It is just created and cat'ed to input.in, and the string 'echo' is included in that output. 它只是创建并输入到input.in,字符串'echo'包含在该输出中。

Try removing the string 'echo' from the heredoc (I assume that your perl output starts with the token K_POINTS). 尝试从heredoc中删除字符串'echo'(我假设你的perl输出以令牌K_POINTS开头)。

ie: 即:

declare RESULT=$(./script.pl 5 5 5)

cat> input.in<<EOF 
  bla bla
  $RESULT 
  EOF

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM