简体   繁体   English

什么是这个bash重定向运算符? “<

[英]what's this bash redirection operator? “<<!”

I saw the following bash code: at 19:00 <<! echo "job 1" 我看到以下bash代码: at 19:00 <<! echo "job 1"at 19:00 <<! echo "job 1" at 19:00 <<! echo "job 1" . at 19:00 <<! echo "job 1" I have two problems: 我有两个问题:

  1. What's this redirection operator: <<! 什么是这个重定向操作符: <<! ?
  2. I wrote the following script code: 我写了以下脚本代码:

     at 19:00 <<! echo "job 1" at 20:00 <<! echo "job 2" 

    When I executed this script, atq command only showed one job, the first one. 当我执行这个脚本时, atq命令只显示了一个作业,第一个作业。 What's the matter? 怎么了? And how should I submit the two jobs via this script correctly? 我应该如何通过此脚本正确提交这两个作业?

From bash reference manual 来自bash参考手册

3.6.6 Here Documents 3.6.6这里的文件

This type of redirection instructs the shell to read input from the current source until a line containing only word (with no trailing blanks) is seen. 这种类型的重定向指示shell从当前源读取输入,直到看到只包含单词(没有尾随空白)的行。 All of the lines read up to that point are then used as the standard input for a command. 然后,读取到该点的所有行都将用作命令的标准输入。

The format of here-documents is: 
     <<[−]word
             here-document
     delimiter

So 所以

  1. You shouldn't need to specify anything after word (in your case ! ) 你不应该在word之后指定任何东西(在你的情况下!
  2. Then you should specify at job on one or more lines 然后,你应该指定at工作中的一个或多个行
  3. Finally, add a line containing word (again, in your case ! ) 最后,添加一行包含word (在您的情况下再次!

The <<! <<! is a here document , as Nya explained. 正如Nya解释的那样,这是一份这里的文件

You should write: 你应该写:

at 19:00 <<!
    echo "job 1"
!
at 20:00 <<!
    echo "job 2"
!

Without the lines starting ! 没有线路开始! , your here document was the rest of the shell script, which is why there was only one command in the atq . ,你的here文件是shell脚本的其余部分,这就是atq只有一个命令的原因。 (But, the command would have scheduled the second job when it ran!) (但是,命令会在它运行时安排第二个工作!)

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

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