This manual page is for Mac OS X version 10.6.3

If you are running a different version of Mac OS X, view the documentation locally:

  • In Terminal, using the man(1) command

Reading manual pages

Manual pages are intended as a quick reference for people who already understand a technology.

  • For more information about the manual page format, see the manual page for manpages(5).

  • For more information about this technology, look for other documentation in the Apple Reference Library.

  • For general information about writing shell scripts, read Shell Scripting Primer.



gets(n)                                     Tcl Built-In Commands                                    gets(n)



____________________________________________________________________________________________________________

NAME
       gets - Read a line from a channel

SYNOPSIS
       gets channelId ?varName?
____________________________________________________________________________________________________________


DESCRIPTION
       This  command  reads  the  next  line  from  channelId, returns everything in the line up to (but not
       including) the end-of-line character(s), and discards the end-of-line character(s).

       ChannelId must be an identifier for an open channel such as the Tcl standard input  channel  (stdin),
       the  return  value  from an invocation of open or socket, or the result of a channel creation command
       provided by a Tcl extension. The channel must have been opened for input.

       If varName is omitted the line is returned as the result of the command.   If  varName  is  specified
       then the line is placed in the variable by that name and the return value is a count of the number of
       characters returned.

       If end of file occurs while scanning for an end of line, the command returns whatever input is avail-able available
       able  up  to  the  end  of file.  If channelId is in nonblocking mode and there is not a full line of
       input available, the command returns an empty string and does not consume any input.  If  varName  is
       specified  and  an  empty string is returned in varName because of end-of-file or because of insuffi-cient insufficient
       cient data in nonblocking mode, then the return count is -1.  Note that if varName is  not  specified
       then  the  end-of-file and no-full-line-available cases can produce the same results as if there were
       an input line consisting only of the end-of-line character(s).  The eof and fblocked commands can  be
       used to distinguish these three cases.

EXAMPLE
       This  example reads a file one line at a time and prints it out with the current line number attached
       to the start of each line.

              set chan [open "some.file.txt"]
              set lineNumber 0
              while {[gets $chan line] >= 0} {
                  puts "[incr lineNumber]: $line"
              }
              close $chan


SEE ALSO
       file(n), eof(n), fblocked(n), Tcl_StandardChannels(3)


KEYWORDS
       blocking, channel, end of file, end of line, line, nonblocking, read



Tcl                                                  7.5                                             gets(n)

Reporting Problems

The way to report a problem with this manual page depends on the type of problem:

Content errors
Report errors in the content of this documentation to the Tcl project.
Bug reports
Report bugs in the functionality of the described tool or API to Apple through Bug Reporter and to the Tcl project through their bug reporting page.
Formatting problems
Report formatting mistakes in the online version of these pages with the feedback links below.

Did this document help you? Yes It's good, but... Not helpful...