When invoked as a program, yash performs the predefined initialization steps and repeatedly reads and executed commands. Command line arguments given in the invocation determines how the shell initializes itself and executes commands.

Command line arguments

The syntax of command line arguments for yash conforms to POSIX. As defined in POSIX, arguments are separated into options and operands. For more detailed explanation about options and operands, see Command argument syntax. All options must come before operands. The interpretation of operands depends on options specified.

When you specify the -c (--cmdline) option, you must give at least one operand. The shell interprets and executes the first operand as a command string. The second operand, if any, is used to initialize the 0 special parameter. The other operands, if any, are used to initialize the positional parameters. When the -c (--cmdline) option is specified, the shell does not read any file or the standard input (unless the dot built-in is used).

If you specify the -s (--stdin) option, the shell reads the standard input, interprets the input as commands, and executes them. All the operands given are used to initialize the positional parameters. The 0 special parameter is initialized to the name the shell is invoked as.

If you specify neither the -c (--cmdline) nor -s (--stdin) option, the shell reads a file, interprets the file contents as commands, and executes them. The first operand specifies the pathname of the file. The remaining operands are used to initialize the positional parameters. If you do not give any operands, the shell reads the standard input as if the -s (--stdin) option is specified.

You cannot use both the -c (--cmdline) and -s (--stdin) options at a time.

If you specify either the --help or -V (--version) option, the shell never performs the usual initialization or command execution. Instead, it just prints brief usage (for --help) or version information (for -V and --version). If the -V (--version) option is accompanied by the -v (--verbose) option, the shell prints a list of the available optional features as well.

If you specify the -i (--interactive) option, the shell goes into the interactive mode. If you specify the +i (++interactive) option, conversely, the shell never goes into the interactive mode.

If you specify the -l (--login) option, the shell behaves as a login shell.

The --noprofile, --norcfile, --profile, and --rcfile options determine how the shell is initialized (see below for details).

In addition to the options described above, you can specify options that can be specified to the set built-in.

If the first operand is - and the options and the operands are not separated by --, the first operand is ignored.

Initialization of yash

Yash initializes itself as follows:

  1. Yash first parses the name it was invoked as. If the name starts with -, the shell behaves as a login shell. If the name is sh (including names such as /bin/sh), the shell goes into the POSIXly-correct mode.

  2. If no operands are given and the standard input and standard error are both connected to a terminal, the shell goes into the interactive mode unless the +i (++interactive) option is specified.

  3. Job control is automatically enabled in an interactive shell unless the +m (++monitor) option is specified.

  4. Yash reads and executes commands from the following files (unless the real and effective user IDs of the shell process are different or the real and effective group IDs of the shell process are different):

    1. If it is behaving as a login shell, the shell reads the file specified by the --profile=filename option unless the --noprofile option is specified or the shell is in the POSIXly-correct mode.
      If the --profile=filename option is not specified, the shell reads ~/.yash_profile as a default.

    2. If in the interactive mode, the shell reads the file specified by the --rcfile=filename option unless the --norcfile option is specified.
      If the --rcfile=filename option is not specified, the shell instead reads the following files:

      • If not in the POSIXly-correct mode, the shell reads ~/.yashrc. If it cannot be read, the shell searches YASH_LOADPATH for a file named initialization/default.

      • If in the POSIXly-correct mode, the shell performs parameter expansion on the value of the ENV environment variable and treats the expansion result as the name of the file to read.

Note
Yash never automatically reads /etc/profile, /etc/yashrc, nor ~/.profile.