gets − Read a line from a channel


gets channelId ?varName? ___________________________


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 available up to the end of file. If channelId is in non-blocking 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 insufficient data in non-blocking 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.


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


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


blocking, channel, end of file, end of line, line, non-blocking, read

More Linux Commands

statd(8) - NSM service daemon (Admin - Linux man page)......
File locks are not part of persistent file system state. Lock state is thus lost when a host reboots. Network file systems must also detect when lock state is l

nohup(1) - run a command immune to hangups, with output to a
Run COMMAND, ignoring hangup signals. --help display this help and exit --version output version information and exit If standard input is a terminal, redirect

aa-audit(8) set an AppArmor security profile to audit mode.
aa-audit is used to set one or more profiles to audit mode. In this mode security policy is enforced and all access (successes and failures) are logged to the s

nc(1) - arbitrary TCP and UDP connections and listens.......
The nc (or netcat) utility is used for just about anything under the sun involving TCP or UDP. It can open TCP connections, send UDP packets, listen on arbitrar

krb5-send-pr(1) - send problem report (PR) to a central supp
krb5-send-pr is a tool used to submit problem reports (PRs) to a central support site. In most cases the correct site will be the default. This argument indicat

transport(5) - Postfix transport table format (Man Page)....
The optional transport(5) table specifies a mapping from email addresses to message delivery transports and next-hop destinations. Message delivery transports s

audit_set_backlog_limit(3) - Set the audit backlog limit....
audit_set_backlog_limit sets the queue length for audit events awaiting transfer to the audit daemon. The default value is 64 which can potentially be overrun b

ausearch_next_event(3) - find the next event that meets sear
ausearch_next_event will scan the input source and evaluate whether any record in an event contains the data being searched for. Evaluation is done at the recor

Shell(3pm) - run shell commands transparently within perl...
Caveats This package is included as a show case, illustrating a few Perl features. It shouldnt be used for production programs. Although it does provide a simpl

XScreenSaverQueryExtension(3) - X11 Screen Saver extension c
The X Window System provides support for changing the image on a display screen after a user-settable period of inactivity to avoid burning the cathode ray tube

glLightf(3gl) - set light source parameters - Linux man page
glLight sets the values of individual light source parameters. light names the light and is a symbolic name of the form GL_LIGHT$i$, where 0 <= i < GL_MAX_LIGHT

gnome-keyring(1) The gnomekeyring commandline tool..........
The gnome-keyring tool can be used to interact with gnome-keyring-daemon. COMMANDS The following commands can be used: import FILE Import keys or certificates f

We can't live, work or learn in freedom unless the software we use is free.