The shell script which is generated by screen is a simple but complete stand-alone program. It paints the screen, uses cursor to move around the screen and prompts the user for input.
screen can be used as a form entry to a table; it can be modified so that its output appended to a table or sent through a pipe; it can read in data and display on the screen; and validation can be added to check user input.
Follow these steps to set up an executable shell program using screen:
$ cat mail.f
Mail List Entry Form
<!date!>
Name : <Name> Company: <Company>
Street: <Street>
City : <City> State : <State> ZIP: <ZIP>
Phone : <Phone>
Everything prints on the screen except what is in angle brackets (< >), which are positions at which variables are read in. Commands surrounded by exclamation marks and angle brackets such as <!date!> are executed when the program is running.
$ screen < mail.f > mail.s $ cat mail.s: paint crt screen exec 3>&1 1>&2 clear cat <<SCREEN Mail List Entry Form Name : Company: Street: City : State : ZIP: Phone : SCREEN
: read user input cursor 01 23 ; date; cursor 03 08 ; read Name; cursor 03 36 ; read Company; cursor 04 08 ; read Street; cursor 05 08 ; read City; cursor 05 36 ; read State; cursor 05 55 ; read ZIP; cursor 06 08 ; read Phone;
: output table head exec 1>&3 echo "Name Company Street City State ZIP Phone" echo "---- ------- ------ ---- ----- --- -----" : append row echo "$Name $Company $Street $City $State $ZIP $Phone"
The resulting shell progam is in three parts. First, the "paint crt screen" section will put the form on the screen after clearing the screen. Second, the "read user input" section will move the cursor to each input field and wait for the user to enter a string of characters which will be assigned to the column variables. Third, the "output table head" section will write out the user input to a table on the standard output.
The exec command sends the screen output to the screen through the third file descriptor, "standard error output," so that the screen program can be used in a pipe. For example, the table can be piped into another program. The "standard error" is usually unbuffered, speeding up output to the screen.
To execute mail.s, first make it executable with the chmod command.
$ chmod +x mail.s $ mail.s > mail.t Mail List Entry Form Wed Sep 4 14:09:30 EDT 1992
Name : Hi Ho Company: Street: 1st St. City : LA State : CA ZIP: 90024 Phone : 213-555-1212
$ cat mail.t Name Company Street City State ZIP Phone ---- ------- ------ ---- ----- --- ----- Hi Ho HH Inc. 1st St. LA CA 90024 213-555-1212
The table output can be directed to a file or pipe. Here it was directed into a table named mail.t. SEE ALSO