Shell Variables Using Shell Variables gsh supports variables in the shell environment. These variables can be used by any shell utility or script. Many EXE files and shell scripts predefine certain shell variables that contain formatting options or other options for a specific utility. As an example, the ls utility looks for the variable TERM that defines the terminal type currently being used. When ls is started, it reads the value of the TERM variable and avoids printing Apple II specific MouseText characters if the set terminal type does not support them. gsh has set aside certain variables for its specific use. Shell utilities should be aware of these variables and use them appropriately. Use caution when changing shell variables, because the change could affect more than just the shell. Scope of Shell Variables There are two types of processes that are involved in any discussion of a multitasking system. The original process, gsh for example, is called a parent process. If gsh invokes a process, such as ls, cp, or mv, that process is called a child process. It is possible for any process to define a variable. These variables will not be made available to other processes unless the program that defined the variable specifically makes them available. The export command makes variables defined by one process available to its children. See the example gshrc shell script shown in . In the case of the shell, most of its variables are exported and, therefore, all shell utilities can read the value of a shell variable. However, programs cannot change the value of a shell variable. In general, executables share their environment with that of the shell, so that a utility can change variables in its parent's environment. This allows communication between programs and the shell. Description of Predefined Shell Variables The following variables have special meaning to gsh. Shell variable names are not case sensitive. $0, $1, $2, ... String values that contain the arguments to a shell script. Variable 0 contains the name of the script. The first argument begins with variable 1 and so on. $< When encountered, the variable is expanded using a value obtained from standard input. This provides a means of obtaining user input in script files. Note that the shell variables are expanded before the command-line is executed (See .) When prompting the user for input, be sure that the prompt is in a separate command-line than the $<. Also, if the user wishes to enter a value with spaces, he must quote what he types with double-quotes. $ECHO A boolean value that, if defined, will cause commands in a shell script to be echoed to standard output. $FIGNORE This variable, if set, contains a list of filename suffixes. When doing command or filename completion, gsh will ignore any filename with a suffix listed in FIGNORE. For example, you might want to set fignore=".A .ROOT .SYM" to ignore object files and other compiler droppings. $HISTORY A numeric value that contains the number of history commands (command-lines) remembered. If the value is 0 or HISTORY is undefined, all commands will be remembered. Previous command-lines can be called back with the UP-ARROW and DOWN-ARROW. (See .) $HOME The HOME directory is the main directory of the shell; it is the directory gsh defaults to when it starts. The tilde ("~") character can be used as a shorthand method of accessing the HOME directory (as discussed in ). $IGNOREEOF A boolean value that, if enabled, will prevent ^D from exiting the shell. $NOBEEP A boolean value that, if set, will prevent gsh from sounding the speaker when errors occur while editing a command-line. $NODIREXEC A boolean value that, if set, will disable gsh's feature of treating directory names as commands; i.e. if a directory is specified as a command, gsh will move to that directory as though the cd command was being used. $NOGLOB A boolean value that, if set, will disable filename globbing. Command arguments will be passed to their commands "as-is", without any wildcard expansion. $NONEWLINE A boolean value that, if set, will disable extraneous carriage returns being output before and after command execution. Examples given in this manual have this option set. $PATH A string value that defines the pathnames where shell scripts, EXE utilities, and SYS16 programs can be found (See ). Because GS/OS uses colons as separators in pathnames, gsh cannot allow colons to be used as separators in the PATH variable, as UNIX does. If one of the path entries has a space within it (which is possible with the HFS FST), then the space should be quoted with a backslash, "\". $PRECMD This is actually a special alias and not an environment variable. If PRECMD is defined then its value is taken as a a command to be executed just before gsh prints the prompt for a command line. For example, alias precmd qtime will print the time in English text before every prompt. $PROMPT When gsh prompts you to enter a command, the prompt that appears before the cursor can be customized for your gsh environment. If PROMPT is undefined, the default prompt of "% " is used. The prompt string recognizes certain character sequences in the PROMPT variable and interprets them accordingly. The following are the special characters: Prompt Special Characters %h, %!, ! current history number %t, %@ current time of day in 12 hour am/pm format %d, %/ current working directory %~ current working directory with tilde replacement %c, %C, %. trailing component of current working directory %S, %s inverse mode on (%s) and off (%S) %U, %u begin and end underline mode (only on terminals that support underline; gnocon will use inverse mode instead) %% the single "%" character %n user name (as defined by $USER) %W date in mm/dd/yy format %D date in yy-mm-dd format \n newline \r carriage return \t horizontal tab \b bell
$PUSHDSILENT If this variable is defined, gsh will not print the directory stack after any of the directory stack commands. (See pushd and popd in .) $SAVEHIST A numeric value that contains the number of commands to save to disk when exiting gsh. These commands are then read back in when gsh is restarted which allows old commands to be reused. If the value is 0 or SAVEHIST is undefined, no commands will be saved to disk. $TERM This variable contains the name of the terminal emulation that the shell and other applications should use. By default, it is "gnocon". When the shell encounters a set term command, it automatically calls the the tset to reload the termcap information. See also . $TERMCAP This variable specifies the location of the termcap file. The shell and other applications look for termcap in the /etc directory, but if TERMCAP is set, the fully specified termcap file is used instead. This allows users to install custom termcap entries. See also . $USER A string that represents the login name of the current user. This variable is usually set by login(8).
Accessing Shell Variables Shell variables are defined or changed with the set command. The unset command is used to delete a variable. See for more information on the set and unset commands. To access shell variables from the command line or a shell script, use the character "$" followed by the variable name. The dollar sign character will expand the variable to its value. If you wish to use the dollar sign character in a string from the command line, remember to enclose it in single quotes or use the "\" escape character. If you use double quotes, the shell will try to expand the variable. To differentiate the variable name from characters that may immediately follow it, the variable name may be optionally surrounded with braces, "{" and "}".This provides a very powerful way of user interaction with shell scripts.