Other forms of input to shell variables or commands in a script



Last revision August 6, 2004

You can execute a command from the shell script and have it read the next few lines in the script as the command's standard input. You do this by redirecting the standard input with the special symbol << followed by a "marker" string. The shell reads the lines from the script following this command until it encounters a line that contains only the marker string. All the lines it has read (not counting the marker string line) are then fed to the command as its standard input.

Here is an example of a fragment of code from a shell script using this feature:

You can read a line of input from the standard input of the shell script (usually the terminal, but could be redirected from a file) and set it as the value of a variable with this syntax:
      set variable=$<

This can be used to "prompt" for information from the user. First use the echo command to print a question; then read the answer typed by the user at the terminal with the syntax above.