8.10. Shell Invocation Options

 <  Day Day Up  >  

When the shell is started using the sh command, it can take options to modify its behavior. See Table 8.7.

Table 8.7. Shell Invocation Options

Option

Meaning

“i

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

“s

Commands are read from standard input and output is sent to standard error.

“c string

Commands are read from string.


8.10.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 8.8 for a list of set options.

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

Table 8.8. The set Command Options

Option

Meaning

“a

Marks variables that have been modified or exported

“e

Exits the program if a command returns a nonzero status

“f

Disables globbing (filename expansion)

“h

Locates and remembers function commands as functions when they are defined, not just when they are executed

“k

Places all keyword arguments in the environment for a command, not just those that precede the command name

“n

Reads commands but does not execute them; used for debugging

“t

Exits after reading and executing one command

“u

Treats unset variables as an error when performing substitution

“v

Prints shell input lines as they are read; used for debugging

“x

Prints commands and their arguments as they are being executed; used for debugging

“ “

Does not change any of the flags


EXPLANATION

  1. The f option is turned on; filename expansion is disabled.

  2. The asterisk is not expanded.

  3. The question marks are not expanded.

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

8.10.2 Shell Built-In Commands

The shell has a number of commands that are built into its source code. Because the commands are built-in, the shell doesn't have to locate them on disk, making execution much faster. The built-in commands are listed in Table 8.9.

Table 8.9. Built-In Commands

Command

What It Does

:

Do-nothing command; returns exit status 0

. file

The dot command reads and executes command from file

break [n]

See "The break Command" on page 361

cd

Change directory

continue [n]

See "The continue Command" on page 362

echo [ args ]

Echo arguments

eval command

Shell scans the command line twice before execution

exec command

Runs command in place of this shell

exit [ n ]

Exit the shell with status n

export [ var ]

Make var known to subshells

hash

Controls the internal hash table for quicker searches for commands

kill [ “signal process ]

Sends the signal to the PID number or job number of the process; see /usr/include/sys/signal.h for a list of signals

getopts

Used in shell scripts to parse command line and check for legal options

login [ username ]

Sign onto the system

newgrp [ arg ]

Logs a user into a new group by changing the real group and effective group ID

pwd

Print present working directory

read [ var ]

Read line from standard input into variable var

readonly [ var ]

Make variable var read-only; cannot be reset

return [ n ]

Return from a function where n is the exit value given to the return

set

See Table 8.8

shift [ n ]

Shift positional parameters to the left n times

stop pid

Halt execution of the process number PID

suspend

Stops execution of the current shell (but not if a login shell)

times

Print accumulated user and system times for processes run from this shell

trap [ arg ] [ n ]

When shell receives signal n ( 0, 1, 2, or 15 ), execute arg

type [ command ]

Prints the type of command; for example, pwd has a built-in shell, in ksh , an alias for the command whence “v

umask [ octal digits ]

User file creation mode mask for owner, group, and others

unset [ name ]

Unset value of variable or function

wait [ pid#n ]

Wait for background process with PID number n and report termination status

ulimit [ options size ]

Set maximum limits on processes

umask [ mask ]

Without argument, print out file creation mask for permissions

wait [ pid#n ]

Wait for background process with PID number n and report termination status


 <  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