<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html40/loose.dtd"> <HTML> <!-- Created on August, 9 2002 by texi2html 1.65 --> <!-- Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author) Karl Berry <karl@freefriends.org> Olaf Bachmann <obachman@mathematik.uni-kl.de> and many others. Maintained by: Olaf Bachmann <obachman@mathematik.uni-kl.de> Send bugs and suggestions to <texi2html@mathematik.uni-kl.de> --> <HEAD> <TITLE>zsh: Invocation</TITLE> <META NAME="description" CONTENT="zsh: Invocation"> <META NAME="keywords" CONTENT="zsh: Invocation"> <META NAME="resource-type" CONTENT="document"> <META NAME="distribution" CONTENT="global"> <META NAME="Generator" CONTENT="texi2html 1.65"> </HEAD> <BODY LANG="en" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000"> <A NAME="SEC11"></A> <TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0> <TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_2.html#SEC10"> < </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_3.html#SEC12"> > </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_2.html#SEC3"> << </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh.html#SEC_Top"> Up </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_4.html#SEC15"> >> </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh.html#SEC_Top">Top</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_toc.html#SEC_Contents">Contents</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_24.html#SEC195">Index</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_abt.html#SEC_About"> ? </A>]</TD> </TR></TABLE> <H1> 3. Invocation </H1> <!--docid::SEC11::--> <A NAME="IDX6"></A> <P> <HR SIZE="6"> <A NAME="SEC12"></A> <TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0> <TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_3.html#SEC11"> < </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_3.html#SEC13"> > </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_3.html#SEC11"> << </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh.html#SEC_Top"> Up </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_4.html#SEC15"> >> </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh.html#SEC_Top">Top</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_toc.html#SEC_Contents">Contents</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_24.html#SEC195">Index</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_abt.html#SEC_About"> ? </A>]</TD> </TR></TABLE> <H2> 3.1 Invocation Options </H2> <!--docid::SEC12::--> <A NAME="IDX7"></A> <A NAME="IDX8"></A> The following flags are interpreted by the shell when invoked to determine where the shell will read commands from: <P> </P> <DL COMPACT> <DT><TT>-c</TT> <DD>Take the first argument as a command to execute, rather than reading commands from a script or standard input. If any further arguments are given, the first one is assigned to <TT>$0</TT>, rather than being used as a positional parameter. <P> </P> <DT><TT>-i</TT> <DD>Force shell to be interactive. <P> </P> <DT><TT>-s</TT> <DD>Force shell to read commands from the standard input. If the <TT>-s</TT> flag is not present and an argument is given, the first argument is taken to be the pathname of a script to execute. <P> </DL> <P> After the first one or two arguments have been appropriated as described above, the remaining arguments are assigned to the positional parameters. </P> <P> For further options, which are common to invocation and the <TT>set</TT> builtin, see <A HREF="zsh_15.html#SEC74">15. Options</A>. </P> <P> Options may be specified by name using the <TT>-o</TT> option. <TT>-o</TT> acts like a single-letter option, but takes a following string as the option name. For example, </P> <P> <TABLE><tr><td> </td><td class=example><pre>zsh -x -o shwordsplit scr </pre></td></tr></table><P> runs the script <TT>scr</TT>, setting the <TT>XTRACE</TT> option by the corresponding letter `<TT>-x</TT>' and the <TT>SH_WORD_SPLIT</TT> option by name. Options may be turned <EM>off</EM> by name by using <TT>+o</TT> instead of <TT>-o</TT>. <TT>-o</TT> can be stacked up with preceding single-letter options, so for example `<TT>-xo shwordsplit</TT>' or `<TT>-xoshwordsplit</TT>' is equivalent to `<TT>-x -o shwordsplit</TT>'. </P> <P> Options may also be specified by name in GNU long option style, `<TT>--</TT><VAR>option-name</VAR>'. When this is done, `<TT>-</TT>' characters in the option name are permitted: they are translated into `<TT>_</TT>', and thus ignored. So, for example, `<TT>zsh --sh-word-split</TT>' invokes zsh with the <TT>SH_WORD_SPLIT</TT> option turned on. Like other option syntaxes, options can be turned off by replacing the initial `<TT>-</TT>' with a `<TT>+</TT>'; thus `<TT>+-sh-word-split</TT>' is equivalent to `<TT>--no-sh-word-split</TT>'. Unlike other option syntaxes, GNU-style long options cannot be stacked with any other options, so for example `<TT>-x-shwordsplit</TT>' is an error, rather than being treated like `<TT>-x --shwordsplit</TT>'. </P> <P> The special GNU-style option `<TT>--version</TT>' is handled; it sends to standard output the shell's version information, then exits successfully. `<TT>--help</TT>' is also handled; it sends to standard output a list of options that can be used when invoking the shell, then exits successfully. </P> <P> Option processing may be finished, allowing following arguments that start with `<TT>-</TT>' or `<TT>+</TT>' to be treated as normal arguments, in two ways. Firstly, a lone `<TT>-</TT>' (or `<TT>+</TT>') as an argument by itself ends option processing. Secondly, a special option `<TT>--</TT>' (or `<TT>+-</TT>'), which may be specified on its own (which is the standard POSIX usage) or may be stacked with preceding options (so `<TT>-x-</TT>' is equivalent to `<TT>-x --</TT>'). Options are not permitted to be stacked after `<TT>--</TT>' (so `<TT>-x-f</TT>' is an error), but note the GNU-style option form discussed above, where `<TT>--shwordsplit</TT>' is permitted and does not end option processing. </P> <P> Except when the <CITE>sh</CITE>/<CITE>ksh</CITE> emulation single-letter options are in effect, the option `<TT>-b</TT>' (or `<TT>+b</TT>') ends option processing. `<TT>-b</TT>' is like `<TT>--</TT>', except that further single-letter options can be stacked after the `<TT>-b</TT>' and will take effect as normal. </P> <P> <TABLE BORDER="0" CELLSPACING="0"> <TR><TD ALIGN="left" VALIGN="TOP"><A HREF="zsh_3.html#SEC13">3.2 Compatibility</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP"></TD></TR> <TR><TD ALIGN="left" VALIGN="TOP"><A HREF="zsh_3.html#SEC14">3.3 Restricted Shell</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP"></TD></TR> </TABLE> <P> <A NAME="Compatibility"></A> </P> <P> <HR SIZE="6"> <A NAME="SEC13"></A> <TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0> <TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_3.html#SEC12"> < </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_3.html#SEC14"> > </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_3.html#SEC11"> << </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_3.html#SEC11"> Up </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_4.html#SEC15"> >> </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh.html#SEC_Top">Top</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_toc.html#SEC_Contents">Contents</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_24.html#SEC195">Index</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_abt.html#SEC_About"> ? </A>]</TD> </TR></TABLE> <H2> 3.2 Compatibility </H2> <!--docid::SEC13::--> <A NAME="IDX9"></A> <A NAME="IDX10"></A> <A NAME="IDX11"></A> Zsh tries to emulate <CITE>sh</CITE> or <CITE>ksh</CITE> when it is invoked as <TT>sh</TT> or <TT>ksh</TT> respectively; more precisely, it looks at the first letter of the name by which it was invoked, excluding any initial `<TT>r</TT>' (assumed to stand for `restricted'), and if that is `<TT>s</TT>' or `<TT>k</TT>' it will emulate <CITE>sh</CITE> or <CITE>ksh</CITE>. Furthermore, if invoked as <TT>su</TT> (which happens on certain systems when the shell is executed by the <TT>su</TT> command), the shell will try to find an alternative name from the <TT>SHELL</TT> environment variable and perform emulation based on that. <P> In <CITE>sh</CITE> and <CITE>ksh</CITE> compatibility modes the following parameters are not special and not initialized by the shell: <TT>ARGC</TT>, <TT>argv</TT>, <TT>cdpath</TT>, <TT>fignore</TT>, <TT>fpath</TT>, <TT>HISTCHARS</TT>, <TT>mailpath</TT>, <TT>MANPATH</TT>, <TT>manpath</TT>, <TT>path</TT>, <TT>prompt</TT>, <TT>PROMPT</TT>, <TT>PROMPT2</TT>, <TT>PROMPT3</TT>, <TT>PROMPT4</TT>, <TT>psvar</TT>, <TT>status</TT>, <TT>watch</TT>. </P> <P> The usual zsh startup/shutdown scripts are not executed. Login shells source <TT>/etc/profile</TT> followed by <TT>$HOME/.profile</TT>. If the <TT>ENV</TT> environment variable is set on invocation, <TT>$ENV</TT> is sourced after the profile scripts. The value of <TT>ENV</TT> is subjected to parameter expansion, command substitution, and arithmetic expansion before being interpreted as a pathname. Note that the <TT>PRIVILEGED</TT> option also affects the execution of startup files. </P> <P> The following options are set if the shell is invoked as <TT>sh</TT> or <TT>ksh</TT>: <TT>NO_BAD_PATTERN</TT>, <TT>NO_BANG_HIST</TT>, <TT>NO_BG_NICE</TT>, <TT>NO_EQUALS</TT>, <TT>NO_FUNCTION_ARGZERO</TT>, <TT>GLOB_SUBST</TT>, <TT>NO_GLOBAL_EXPORT</TT>, <TT>NO_HUP</TT>, <TT>INTERACTIVE_COMMENTS</TT>, <TT>KSH_ARRAYS</TT>, <TT>NO_MULTIOS</TT>, <TT>NO_NOMATCH</TT>, <TT>NO_NOTIFY</TT>, <TT>POSIX_BUILTINS</TT>, <TT>NO_PROMPT_PERCENT</TT>, <TT>RM_STAR_SILENT</TT>, <TT>SH_FILE_EXPANSION</TT>, <TT>SH_GLOB</TT>, <TT>SH_OPTION_LETTERS</TT>, <TT>SH_WORD_SPLIT</TT>. Additionally the <TT>BSD_ECHO</TT> and <TT>IGNORE_BRACES</TT> options are set if zsh is invoked as <TT>sh</TT>. Also, the <TT>KSH_OPTION_PRINT</TT>, <TT>LOCAL_OPTIONS</TT>, <TT>PROMPT_BANG</TT>, <TT>PROMPT_SUBST</TT> and <TT>SINGLE_LINE_ZLE</TT> options are set if zsh is invoked as <TT>ksh</TT>. <A NAME="Restricted Shell"></A> </P> <P> <HR SIZE="6"> <A NAME="SEC14"></A> <TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0> <TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_3.html#SEC13"> < </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_4.html#SEC15"> > </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_3.html#SEC11"> << </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_3.html#SEC11"> Up </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_4.html#SEC15"> >> </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh.html#SEC_Top">Top</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_toc.html#SEC_Contents">Contents</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_24.html#SEC195">Index</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_abt.html#SEC_About"> ? </A>]</TD> </TR></TABLE> <H2> 3.3 Restricted Shell </H2> <!--docid::SEC14::--> <A NAME="IDX12"></A> <A NAME="IDX13"></A> When the basename of the command used to invoke zsh starts with the letter `<TT>r</TT>' or the `<TT>-r</TT>' command line option is supplied at invocation, the shell becomes restricted. Emulation mode is determined after stripping the letter `<TT>r</TT>' from the invocation name. The following are disabled in restricted mode: <P> <UL> <LI> changing directories with the <TT>cd</TT> builtin <LI> changing or unsetting the <TT>PATH</TT>, <TT>path</TT>, <TT>MODULE_PATH</TT>, <TT>module_path</TT>, <TT>SHELL</TT>, <TT>HISTFILE</TT>, <TT>HISTSIZE</TT>, <TT>GID</TT>, <TT>EGID</TT>, <TT>UID</TT>, <TT>EUID</TT>, <TT>USERNAME</TT>, <TT>LD_LIBRARY_PATH</TT>, <TT>LD_AOUT_LIBRARY_PATH</TT>, <TT>LD_PRELOAD</TT> and <TT>LD_AOUT_PRELOAD</TT> parameters <LI> specifying command names containing <TT>/</TT> <LI> specifying command pathnames using <TT>hash</TT> <LI> redirecting output to files <LI> using the <TT>exec</TT> builtin command to replace the shell with another command <LI> using <TT>jobs -Z</TT> to overwrite the shell process' argument and environment space <LI> using the <TT>ARGV0</TT> parameter to override <TT>argv[0]</TT> for external commands <LI> turning off restricted mode with <TT>set +r</TT> or <TT>unsetopt RESTRICTED</TT> </UL> <P> These restrictions are enforced after processing the startup files. The startup files should set up <TT>PATH</TT> to point to a directory of commands which can be safely invoked in the restricted environment. They may also add further restrictions by disabling selected builtins. </P> <P> Restricted mode can also be activated any time by setting the <TT>RESTRICTED</TT> option. This immediately enables all the restrictions described above even if the shell still has not processed all startup files. <A NAME="Files"></A> </P> <P> <HR SIZE="6"> <TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0> <TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_3.html#SEC11"> << </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_4.html#SEC15"> >> </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh.html#SEC_Top">Top</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_toc.html#SEC_Contents">Contents</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_24.html#SEC195">Index</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="zsh_abt.html#SEC_About"> ? </A>]</TD> </TR></TABLE> <BR> <FONT SIZE="-1"> This document was generated by <I>Peter Stephenson</I> on <I>August, 9 2002</I> using <A HREF="http://www.mathematik.uni-kl.de/~obachman/Texi2html "><I>texi2html</I></A> </FONT> </BODY> </HTML>