13.19. Shell Invocation Options

 <  Day Day Up  >  

When the shell is started using the bash command, it can take options to modify its behavior. There are two types of options: single-character options and multicharacter options. The single-character options consist of a single leading dash followed by a single character. The multicharacter options consist of two leading dashes and any number of characters . Multicharacter options must appear before single-character options. An interactive login shell normally starts up with “i (starts an interactive shell), “s (reads from standard input), and “m (enables job control). See Table 13.25.

Table 13.25. Bash 2.x Shell Invocation Options

Option

Meaning

“c string

Commands are read from string . Any arguments after string are assigned to positional parameters, starting at $0 .

“D

A list of double quoted strings, preceded by a $ , are printed to standard output. These strings are subject to language translation when the current locale is not C or POSIX.

“i

Shell is in the interactive mode. TERM , QUIT , and INTERRUPT are ignored.

“s

Commands are read from standard input and allows the setting of positional parameters

“r

Starts a restricted shell.

“ “

Signals the end of options and disables further option processing. Any arguments after “ “ or are treated as filenames and arguments.

“ “dump “strings

Same as “D .

“ “help

Displays a usage message for a built-in command and exits.

“ “login

Causes bash to be invoked as a login shell.

“ “noediting

When bash is running interactively, does not use the Readline library.

“ “noprofile

When starting up, bash does not read the initialization files: /etc/profile , ~/.bash_profile , ~/.bash_login , or ~/.profile .

“ “norc

For interactive shells , bash will not read the ~/.bashrc file. Turned on by default, if running shell as sh .

“ “posix

Changes the behavior of bash to match the POSIX 1003.2 standard, if otherwise it wouldn't.

“ “quiet

Displays no information at shell startup, the default.

“ “rcfile file

If bash is interactive, uses this intialization file instead of ~/.bashrc .

“ “restricted

Starts a restricted shell.

“ “verbose

Turns on verbose; same as “v .

“ “version

Displays version information about this bash shell and exits.


13.19.1 The set Command and Options

The set command can be used to turn shell options on and off, as well as for handling command-line arguments. To turn an option on, the dash ( ) is prepended to the option; to turn an option off, the plus sign ( + ) is prepended to the option. See Table 13.26 for a list of set options.

Example 13.90.
 1   $  set -f  2   $  echo *   *  3   $  echo ??   ??  4   $  set +f  

Table 13.26. The Built-In set Command Options

Name of Option

Shortcut Switch

What It Does

allexport

“a

Automatically marks new or modified variables for export from the time the option is set until unset.

braceexpand

“B

Enables brace expansion, and is a default setting.

emacs

 

For command-line editing, uses the emacs built-in editor, and is a default setting.

errexit

“e

If a command returns a nonzero exit status (fails), exits. Not set when reading initialization files.

histexpand

“H

Enables ! and !! when performing history substitution, and is a default setting.

history

 

Enables command-line history; on by default.

ignoreeof

 

Disables EOF (Ctrl-D) from exiting a shell; must type exit . Same as setting shell variable, IGNOREEOF=10 .

keyword

“k

Places keyword arguments in the environment for a command.

interactive_comments

 

For interactive shells, a leading # is used to comment out any text remaining on the line.

monitor

“m

Allows job control.

noclobber

“C

Protects files from being overwritten when redirection is used.

noexec

“n

Reads commands, but does not execute them. Used to check the syntax of scripts. Not on when running interactively.

noglob

“d

Disables pathname expansion (i.e., turns off wildcards).

notify

“b

Notifies user when background job finishes.

nounset

“u

Displays an error when expanding a variable that has not been set

onecmd

“t

Exits after reading and executing one command.

physical

“P

If set, does not follow symbolic links when typing cd or pwd . The physical directory is used instead.

posix

 

Shell behavior is changed if the default operation doesn't match the POSIX standard.

privileged

“p

When set, the shell does not read the .profile or ENV file and shell functions are not inherited from the environment; automatically set for setuid scripts.

verbose

“v

Turns on the verbose mode for debugging.

vi

 

For command-line editing, uses the vi built-in editor.

xtrace

“x

Turns on the echo mode for debugging.


EXPLANATION

  1. The f option is turned on, disabling filename expansion.

  2. The asterisk is not expanded.

  3. The question marks are not expanded.

  4. The f is turned off; filename expansion is enabled.

13.19.2 The shopt Command and Options

The shopt ( bash 2.x) command can also be used to turn shell options on and off.

 <  Day Day Up  >  


UNIX Shells by Example
UNIX Shells by Example (4th Edition)
ISBN: 013147572X
EAN: 2147483647
Year: 2004
Pages: 454
Authors: Ellie Quigley

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net