/usr/bin/jsh [ -acefhiknprstuvx ] [ argument...]
/usr/bin/sh is a command programming language that executes commands read from a terminal or a file. The command jsh is an interface to the shell which provides all of the functionality of sh and enables Job Control (see ‘‘Job Control,’’ below). See ‘‘Invocation,’’ below for the meaning of arguments to the shell.
A pipeline is a sequence of one or more commands separated by |. The standard output of each command but the last is connected by a pipe(2) to the standard input of the next command. Each command is run as a separate process; the shell waits for the last command to terminate. The exit status of a pipeline is the exit status of the last command in the pipeline.
A list is a sequence of one or more pipelines separated by ;, &, &&, or ||, and optionally terminated by ; or &. Of these four symbols, ; and & have equal precedence, which is lower than that of && and ||. The symbols && and || also have equal precedence. A semicolon (;) causes sequential execution of the preceding pipeline (that is, the shell waits for the pipeline to finish before executing any commands following the semicolon); an ampersand (&) causes asynchronous execution of the preceding pipeline (that is, the shell does not wait for that pipeline to finish). The symbol && (||) causes the list following it to be executed only if the preceding pipeline returns a zero (non-zero) exit status. An arbitrary number of newlines may appear in a list, instead of semicolons, to delimit commands.
A command is either a simple-command or one of the following. Unless otherwise stated, the value returned by a command is that of the last simple-command executed in the command.
if list ; then list ; [ elif list ; then list ; ] ... [ else list ; ] fi
The list following if is executed and, if it returns a zero exit status, the list following the first then is executed. Otherwise, the list following elif is executed and, if its value is zero, the list following the next then is executed. Failing that, the else list is executed. If no else list or then list is executed, then the if command returns a zero exit status.
The following words are only recognized as the first word of a command and when not quoted:
if then else elif fi case esac for while until do done { }
No interpretation is done on the string before the string is read, except to remove backslashes (\) used to escape other characters. Backslashes may be used to escape a grave accent (‘) or another backslash (\) and are removed before the command string is read. Escaping grave accents allows nested command substitution. If the command substitution lies within a pair of double quotes (" ...‘ ...‘ ... "), a backslash used to escape a double quote (\") will be removed; otherwise, it will be left intact.
If a backslash is used to escape a newline character (\newline), both the backslash and the newline are removed (see the later section on ‘‘Quoting’’). In addition, backslashes used to escape dollar signs (\$) are removed. Since no parameter substitution is done on the command string before it is read, inserting a backslash to escape a dollar sign has no effect. Backslashes that precede characters other than \, ‘, ", newline, and $ are left intact when the command string is read.
name=value K name=value ...
Pattern-matching is not performed on value. There cannot be a function and a variable with the same name.
In the above, word is not evaluated unless it is to be used as the substituted string, so that, in the following example, pwd is executed only if d is not set or is null:
echo ${d:-‘pwd‘}
If the colon (:) is omitted from the above expressions, the shell only checks whether parameter is set or not.
The following parameters are automatically set by the shell.
- #
- The number of positional parameters in decimal.
- -
- Flags supplied to the shell on invocation or by the set command.
- ?
- The decimal value returned by the last synchronously executed command.
- $
- The process number of this shell.
- !
- The process number of the last background command invoked.
The following parameters are used by the shell. The parameters in this section are also referred to as environment variables.
- HOME
- The default argument (home directory) for the cd command, set to the user’s login directory by login(1) from the password file (see passwd(4) ).
- PATH
- The search path for commands (see ‘‘Execution,’’ below).
- CDPATH
- The search path for the cd command.
- If this parameter is set to the name of a mail file and the MAILPATH parameter is not set, the shell informs the user of the arrival of mail in the specified file.
- MAILCHECK
- This parameter specifies how often (in seconds) the shell will check for the arrival of mail in the files specified by the MAILPATH or MAIL parameters. The default value is 600 seconds (10 minutes). If set to 0, the shell will check before each prompt.
- MAILPATH
- A colon (:) separated list of file names. If this parameter is set, the shell informs the user of the arrival of mail in any of the specified files. Each file name can be followed by % and a message that will be printed when the modification time changes. The default message is you have mail .
- PS1
- Primary prompt string, by default ‘‘.SB $ ’’.
- PS2
- Secondary prompt string, by default ‘‘ > ’’.
- IFS
- Internal field separators, normally space, tab, and newline (see ‘‘Blank Interpretation’’).
- SHACCT
- If this parameter is set to the name of a file writable by the user, the shell will write an accounting record in the file for each shell procedure executed.
- SHELL
- When the shell is invoked, it scans the environment (see ENVIRONMENT, below) for this name.
- LC_CTYPE
- Determines how the shell handles characters. When LC_CTYPE is set to a valid value, the shell can display and handle text and filenames containing valid characters for that locale. The shell can display and handle Extended Unix Code (EUC) characters where any individual character can be 1, 2, or 3 bytes wide. The shell can also handle EUC characters of 1, 2, or more column widths. In the "C" locale, only characters from ISO 8859-1 are valid.
- LC_MESSAGES
- Determines how diagnostic and informative messages are presented. This includes the language and style of the messages, and the correct form of affirmative and negative responses. In the "C" locale, the messages are presented in the default form found in the program itself (in most cases, U.S. English).
If LC_CTYPE and LC_MESSAGES (see environ(5) ) are not set in the environment, the operational behavior of the shell for each corresponding locale category is determined by the value of the LANG environment variable. If LC_ALL is set, its contents are used to override both the LANG and the other LC_* variables. If none of the above variables is set in the environment, the "C" (U.S. style) locale determines how the shell behaves.
The shell gives default values to PATH , PS1 , PS2 , MAILCHECK , and IFS . HOME and MAIL are set by login(1) .
- leading tabs are stripped from word before the shell input is read (but after parameter and command substitution is done on word),
- leading tabs are stripped from the shell input as it is read and before each line is compared with word, and
- shell input is read up to the first line that literally matches the resulting word, or to an EOF .
If any character of word is quoted (see ‘‘Quoting,’’ later), no additional processing is done to the shell input. If no characters of word are quoted:
- parameter and command substitution occurs,
- (escaped) \newlines are removed, and
- \ must be used to quote the characters \, $, and ‘.
The resulting document becomes the standard input.
If any of the above is preceded by a digit, the file descriptor which will be associated with the file is that specified by the digit (instead of the default 0 or 1). For example:
... 2>&1
associates file descriptor 2 with the file currently
associated with file descriptor 1.
The order in which redirections are specified is significant. The shell evaluates redirections left-to-right. For example:
... 1>xxx 2>&1
first associates file descriptor 1 with file xxx. It associates file descriptor 2 with the file associated with file descriptor 1 (that is, xxx). If the order of redirections were reversed, file descriptor 2 would be associated with the terminal (assuming file descriptor 1 had been) and file descriptor 1 would be associated with file xxx.
Using the terminology introduced on the first page, under ‘‘Commands,’’ if a command is composed of several simple commands, redirection will be evaluated for the entire command before it is evaluated for each simple command. That is, the shell evaluates redirection for the entire list, then each pipeline within the list, then each command within each pipeline, then each list within each command.
If a command is followed by & the default standard input for the command is the empty file /dev/null. Otherwise, the environment for the execution of a command contains the file descriptors of the invoking shell as modified by input/output specifications.
- *
- Matches any string, including the null string.
- ?
- Matches any single character.
- K...
- Matches any one of the enclosed characters. A pair of characters separated by - matches any character lexically between the pair, inclusive. If the first character following the opening K is a !, any character not enclosed is matched.
Note: All quoted characters (see below) must be matched explicitly in a filename.
; & ( ) | ^ < > newline space tab
A character may be quoted (that is, made to stand for itself) by preceding it with a backslash (\) or inserting it between a pair of quote marks ( or ""). During processing, the shell may quote certain characters to prevent them from taking on a special meaning. Backslashes used to quote a single character are removed from the word before the command is executed. The pair \newline is removed from a word before command and parameter substitution.
All characters enclosed between a pair of single quote marks (), except a single quote, are quoted by the shell. Backslash has no special meaning inside a pair of single quotes. A single quote may be quoted inside a pair of double quote marks (for example, ""), but a single quote can not be quoted inside a pair of single quotes.
Inside a pair of double quote marks (""), parameter and command substitution occurs and the shell quotes the results to avoid blank interpretation and file name generation. If $* is within a pair of double quotes, the positional parameters are substituted and quoted, separated by quoted spaces ("$1 $2 ..."); however, if $@ is within a pair of double quotes, the positional parameters are substituted and quoted, separated by unquoted spaces ("$1" "$2" ... ). \ quotes the characters \, ‘, , and $. The pair \newline is removed before parameter and command substitution. If a backslash precedes characters other than \, ‘, , $, and newline, then the backslash itself is quoted by the shell.
The environment for any simple-command may be augmented by prefixing it with one or more assignments to parameters. Thus:
TERM=450 command
and
(export TERM; TERM=450; command)
are equivalent as far as the execution of command is concerned if command is not a Special Command. If command is a Special Command, then
will modify the TERM variable in the current shell.TERM=450 command
If the -k flag is set, all keyword arguments are placed in the environment, even if they occur after the command name. The following example first prints a=b c and c:
echo a=b c a=b c set -k echo a=b c c
Each time a command is executed, the command substitution, parameter substitution, blank interpretation, input/output redirection, and filename generation listed above are carried out. If the command name matches the name of a defined function, the function is executed in the shell process (note how this differs from the execution of shell script files, which require a sub-shell for invocation). If the command name does not match the name of a defined function, but matches one of the Special Commands listed below, it is executed in the shell process. The positional parameters $1, $2, .... are set to the arguments of the function. If the command name matches neither a Special Command nor the name of a defined function, a new process is created and an attempt is made to execute the command via exec(2) .
The shell parameter PATH defines the search path for the directory containing the command. Alternative directory names are separated by a colon (:). The default path is /usr/bin. The current directory is specified by a null path name, which can appear immediately after the equal sign, between two colon delimiters anywhere in the path list, or at the end of the path list. If the command name contains a / the search path is not used. Otherwise, each directory in the path is searched for an executable file. If the file has execute permission but is not an a.out file, it is assumed to be a file containing shell commands. A sub-shell is spawned to read it. A parenthesized command is also executed in a sub-shell.
The location in the search path where a command was found is remembered by the shell (to help avoid unnecessary execs later). If the command was found in a relative directory, its location must be re-determined whenever the current directory changes. The shell forgets all remembered locations whenever the PATH variable is changed or the hash -r command is executed (see below).
Using + rather than - causes these flags to be turned off. These flags can also be used upon invocation of the shell. The current set of flags may be found in $-. The remaining arguments are positional parameters and are assigned, in order, to $1, $2, .... If no arguments are given the values of all names are printed.
If limit is not present, ulimit prints the specified limits. Any number of limits may be printed at one time. The -a option prints all limits.
If limit is present, ulimit sets the specified limit to limit. The string unlimited requests the largest valid limit. Limits may be set for only one resource at a time. Any user may set a soft limit to any value below the hard limit. Any user may lower a hard limit. Only a super-user may raise a hard limit; see su(1M) .
The -H option specifies a hard limit. The -S option specifies a soft limit. If neither option is specified, ulimit will set both limits and print the soft limit.
The following options specify the resource whose limits are to be printed or set. If no option is specified, the file size limit is printed or set.
(Run the sysdef(1M) command to obtain the maximum possible limits for your system. The values reported are in hexidecimal, but can be translated into decimal numbers using the bc(1) command. Also, see swap(1M) .)
- -c
- maximum core file size (in 512-byte blocks)
- -d
- maximum size of data segment or heap (in kbytes)
- -f
- maximum file size (in 512-byte blocks)
- -n
- maximum file descriptor plus 1
- -s
- maximum size of stack segment (in kbytes)
- -t
- maximum CPU time (in seconds)
- -v
- maximum size of virtual memory (in kbytes)
Example of ulimit: to
limit the size of a core file dump to 0 Megabytes, type the following:
ulimit -c 0
The remaining flags
and arguments are described under the set command above.
With Job Control enabled every command or pipeline the user enters at the terminal is called a job. All jobs exist in one of the following states: foreground, background or stopped. These terms are defined as follows: 1) a job in the foreground has read and write access to the controlling terminal; 2) a job in the background is denied read access and has conditional write access to the controlling terminal (see stty(1) ); 3) a stopped job is a job that has been placed in a suspended state, usually as a result of a SIGTSTP signal (see signal(5) ).
Every job that the shell starts is assigned a positive integer, called a job number which is tracked by the shell and will be used as an identifier to indicate a specific job. Additionally the shell keeps track of the current and previous jobs. The current job is the most recent job to be started or restarted. The previous job is the first non-current job.
The acceptable syntax for a Job Identifier is of the form:
%jobid
where, jobid may be specified in any of the following formats:
- % or +
- for the current job
- -
- for the previous job
- ?<string>
- specify the job for which the command line uniquely contains string.
- n
- for job number n, where n is a job number
- pref
- where pref is a unique prefix of the command name (for example, if the command ls -l name were running in the background, it could be referred to as %ls); pref cannot contain blanks unless it is quoted.
When Job Control is enabled, the following commands are added to the user’s environment to manipulate jobs:
There are stopped jobs.
This is the only message. If another exit attempt is made, and there are still stopped jobs they will be sent a SIGHUP signal from the kernel and the shell is exited.
Because commands in pipelines are run as separate processes, variables set in a pipeline have no effect on the parent shell.
If you get the error message cannot fork,too many processes, try using the wait(1) command to clean up your background processes. If this doesn’t help, the system process table is probably full or you have too many active foreground processes. (There is a limit to the number of process ids associated with your login, and to the number the system can keep track of.)
Only the last process in a pipeline can be waited for.
If a command is executed, and a command with the same name is installed in a directory in the search path before the directory where the original command was found, the shell will continue to exec the original command. Use the hash command to correct this situation.
The Bourne shell has a limitation on the effective UID for a process. If this UID is less than 100 (and not equal to the process’ real UID ), then the UID is reset to the process’ real UID .
Because the shell implements both foreground and background jobs in the same process group, they all receive the same signals, which can lead to unexpected behavior. It is, therefore, recommended that other job contrl shells be used, especially in an interactive environment.