WIZARDELF
WIZARDELF

Reputation: 3885

what's this bash redirection operator? "<<!"

I saw the following bash code: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. What's the matter? And how should I submit the two jobs via this script correctly?

Upvotes: 4

Views: 4263

Answers (2)

Alexander Putilin
Alexander Putilin

Reputation: 2342

From bash reference manual

3.6.6 Here Documents

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. 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 !)
  2. Then you should specify at job on one or more lines
  3. Finally, add a line containing word(again, in your case !)

Upvotes: 6

Jonathan Leffler
Jonathan Leffler

Reputation: 753695

The <<! is a here document, as Nya explained.

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. (But, the command would have scheduled the second job when it ran!)

Upvotes: 5

Related Questions