0

I am trying to understand part of a shell script that appears to be very confusing for me.

This is the snippet. My questions are:

a) what does <<- do? Is it like a standard expression . I am only aware of > , >> and < for redirection.

b) What could End mean? I am assuming that all the values from 'n' till 'somefilename.dat.summary' is some sort of input that is send to the script 'collapse4' and it's output is redirected to /dev/null which i learned is a place where we send unwanted data.

/usr/can/bin/collapse4<<-End > /dev/null
n
n
1
9 14
y
1
26
8
30
8
1
23
3
1
n
n
y
n
n
somefilename.dat
somefilename.dat.summary
End
fedorqui
  • 275,237
  • 103
  • 548
  • 598
Santhiya
  • 99
  • 2
  • 3
  • 7

1 Answers1

2

This command sends a block of text to /usr/can/bin/collapse4 and redirects the output to /dev/null.

This structure is called here doc. End is the way you "call" the text you are about to insert. Once you are done, you indicate the end of the block with the same word in the very beginning of a new line.

But you can call it whatever. This would do the same:

/usr/can/bin/collapse4<<-HelloJustTesting > /dev/null
n
n
1
...
n
somefilename.dat
somefilename.dat.summary
HelloJustTesting

More information in How can I write a here doc to a file in Bash script?:

In a shell script, you may want to use indentation to make the code readable, however this can have the undesirable effect of indenting the text within your here document. In this case, use use <<- (followed by a dash) to disable leading tabs (Note that to test this you will need to replace the leading whitespace with a tab character, since I cannot print actual tab characters here.)

Community
  • 1
  • 1
fedorqui
  • 275,237
  • 103
  • 548
  • 598