ECHO Statement

The ECHO statement toggles the system echo on the user’s terminal.

Format

ECHO[ON | OFF | expr]

Parameter(s)

ON

Turns system echo on (default).

OFF

Turns system echo off.

expr

An expression evaluating to a numeric value. If expr evaluates to 0, the echo is turned off; if expr evaluates to a number other than 0, the echo is turned on.

Description

The ECHO statement controls the display of input characters on the terminal screen. Normally, all data entered by the user is echoed to the screen as it is typed. The ECHO OFF statement turns off the echo feature, and the ECHO ON statement turns it back on.

If ECHO OFF is specified, subsequent input characters are read by the system as usual, but only control characters (CHAR(1) to CHAR(31)) are displayed to the terminal screen. The ability to turn off character display with ECHO OFF is particularly useful for entering passwords and other confidential information.

The ECHO OFF statement does not affect the echo of control characters for input which is taken directly from the user’s terminal. See INPUT CTRL Statement for information about disabling control characters entirely from user input.

NOTE

The echo feature is not reinstated at the end of a program, so an ECHO OFF statement should be followed by an ECHO ON statement before the end of a program.

Example

In this application the user needs to log on to the program and is prompted for a password, which is kept in a file opened to PASSFILE. The ECHO OFF statement is used before accepting the password, so that it does not appear on the screen.

READ PASSWD FROM PASSFILE , NAME ELSE

   PRINT "LOGON NOT FOUND!"

   STOP

END

PRINT "PASSWORD : " :

ECHO OFF

INPUT PASSWORD

ECHO ON

IF PASSWD < > PASSWORD THEN

   PRINT "SORRY."

   ABORT

END

Note that the ECHO ON statement is executed immediately after the INPUT statement. If ECHO ON had been included any later, then every time the program aborted because of a bad password, the echo feature would remain off when the user returned to TCL.

In the next application a counter ECHO.COUNT is used to simulate the Break Inhibit Counter. Instead of using ECHO ON, the counter is incremented by one and ECHO ECHO.COUNT is executed instead.

Similarly, the counter is decremented by one to turn the echo feature off. By using a counter, programs and subroutines may intermix without danger of a subroutine prematurely reinstating the echo feature.

ECHO.COUNT += 1

ECHO ECHO.COUNT

   .

   .

   .

CALL ACCESS.TEST(ECHO.COUNT)

   .

   .

   .

ECHO.COUNT -= 1

ECHO ECHO.COUNT

STOP

If the subroutine ACCESS.TEST uses the same method of manipulating the echo, the status of the echo feature is maintained throughout the program.

SUBROUTINE ACCESS.TEST(COUNTER)

COUNTER += 1

ECHO COUNTER

   .

   .

   .

COUNTER -= 1

ECHO COUNTER

ENTER

See Also

Statement and Function Reference