GANANCIAS y PÉRDIDAS PATRIMONIALES
2. Segundo paso: Al resultado de la suma anterior le restamos el siguiente importe:
This section describes the following Bourne shell features: • A sample.profilelogin script
• Metacharacters
• Built-in variables and commands
8.3.1
Sample .profile Login Script
If your login shell is the Bourne shell, the operating system executes the .profilelogin script to set up your environment.
The.profile login script variables that are exported are passed to any subshells and subprocesses that are created. Variables that are not exported are used only by the login shell.
In the following.profilelogin script, shell variables are set and exported, a trap is set for the logout script, and the system is instructed to display information. Table 8-8 explains each part of the script.
# Set PATH
PATH=/usr/bin:/usr/local/bin: # Export global variables export PATH
# Set shell variables PS1=’$LOGNAME $ ’ CDPATH=.:..:$HOME
# Set up for logout script
trap "echo logout; $HOME/.logout" 0 # Display status information
date
echo "Currently logged in users:" ; users
Table 8-8: Example Bourne Shell .profile Script
222222222222222222222222222222222222222222222222222222222222222222222222222
Command Description
222222222222222222222222222222222222222222222222222222222222222222222222222
Set Search Path
222222222222222222222222222222222222222222222222222222222222222222222222222 PATH=/usr/bin:/usr/local/bin: Specifies the search path. In this
case,/usr/binis searched first and/usr/local/binsearched second.
222222222222222222222222222222222222222222222222222222222222222222222222222
Export Search Path
222222222222222222222222222222222222222222222222222222222222222222222222222
export PATH Specifies that the search path is to
be passed to all commands that you execute.
222222222222222222222222222222222222222222222222222222222222222222222222222
Set Shell Variables
222222222222222222222222222222222222222222222222222222222222222222222222222 PS1=’$LOGNAME $ ’ PS1is the variable that specifies
the Bourne shell prompt, and its default value is$. However, this variable assignment specifies that your prompt should be changed to the following: username $. For example, if your username were amy, your prompt would be the following: amy $.
CDPATH=.:..:$HOME CDPATHis a variable that sets the
search path for thecdcommand. This variable assignment specifies that thecdcommand should search for the named directory in the current directory (.) first, in the parent directory (..) second, and the home directory ($HOME) third.
222222222222222222222222222222222222222222222222222222222222222222222222222
Set Up Logout Script
222222222222222222222222222222222222222222222222222222222222222222222222222 trap "echo logout; $HOME/.logout" 0 Specifies that your shell should
displaylogoutand execute your .logoutscript when thetrap command captures the exit signal (0).a
Table 8-8: (continued)
222222222222222222222222222222222222222222222222222222222222222222222222222
Command Description
222222222222222222222222222222222222222222222222222222222222222222222222222
Display Status Information
222222222222222222222222222222222222222222222222222222222222222222222222222
date Displays the date and time.
222222222222222222222222222222222222222222222222222222222222222222222222222 Table notes:
a. For more information about thetrapcommand, see Section 7.9.1.
8.3.2
Metacharacters
Table 8-9 describes Bourne shell metacharacters (characters that have special meaning to the shell).
Table 8-9: Bourne Shell Metacharacters
222222222222222222222222222222222222222222222222222222222222222222 Metacharacter Description
222222222222222222222222222222222222222222222222222222222222222222
Syntactic
222222222222222222222222222222222222222222222222222222222222222222 | Separates commands that are part of a pipeline.
&& Runs the next command if current command succeeds. | | Runs the next command if the current command fails. ; Separates commands that should be executed sequentially. ;; Separates elements of a case construct.
& Runs commands in the background.
( ) Groups commands to run as a separate process in a subshell.
222222222222222222222222222222222222222222222222222222222222222222
Filename
222222222222222222222222222222222222222222222222222222222222222222 / Separates the parts of a file’s pathname.
? Matches any single character except a leading dot (.).
Table 8-9: (continued)
222222222222222222222222222222222222222222222222222222222222222222 Metacharacter Description
222222222222222222222222222222222222222222222222222222222222222222 * Matches any sequence of characters except a leading dot
(.).
[ ] Matches any of the enclosed characters.
222222222222222222222222222222222222222222222222222222222222222222
Quotation
222222222222222222222222222222222222222222222222222222222222222222 \ Specifies that the following character should be interpreted
literally; that is, without its special meaning to the shell. ’...’ Specifies that any of the enclosed characters (except for
the’quote character ) should be interpreted literally; that is, without their special meaning to the shell.
"..." Provides a special form of quoting. Specifies that the $ (dollar sign), `(grave accent), and \ (backslash) characters keep their special meaning, while all other enclosed characters are interpreted literally; that is, without their special meaning to the shell. Double quotes are useful in making variable assignments.
222222222222222222222222222222222222222222222222222222222222222222
Input/Output
222222222222222222222222222222222222222222222222222222222222222222 < Redirects input.
> Redirects output to a specified file.
<< Redirects input and specifies that the shell should read input up to a specified line.
>> Redirects output and specifies that the shell should add output to the end of a file.
2> Redirects diagnostic output to a specified file.
222222222222222222222222222222222222222222222222222222222222222222
Substitution
222222222222222222222222222222222222222222222222222222222222222222 ${...} Specifies variable substitution.
‘...‘ Specifies command output substitution.
222222222222222222222222222222222222222222222222222222222222222222
8.3.3
Built-In Variables
The Bourne shell provides variables that can be assigned values. The shell sets some of these variables, and you can set or reset all of them.
Table 8-10 describes selected Bourne shell built-in variables that are of most interest to general users. For complete information on all Bourne Shell built- in variables, see thesh(1) reference page.
Table 8-10: Built-In Bourne Shell Variables
2222222222222222222222222222222222222222222222222222222222222222222 Variable Description
2222222222222222222222222222222222222222222222222222222222222222222 HOME Specifies the name of your login directory, the directory that
becomes the current directory upon completion of a login. Thecdcommand uses the value ofHOMEas its default value. HOMEis set by thelogincommand.
PATH Specifies the directories through which your system should search to find and execute commands. The shell searches these directories in the order specified here. Usually,PATHis set in the.profilefile.
CDPATH Specifies the directories that thecdcommand will search to find the specified argument tocd. Ifcd’s argument is null, or if it begins with a slash ( / ), dot (.), or dot dot (..), then CDPATHis ignored. Usually,CDPATHis set in your .profilefile.
MAIL The pathname of the file where your mail is deposited. You must setMAIL, and this is usually done in your.profile file.
MAILCHECK Specifies in seconds how often the shell checks for mail (600 seconds is the default). If the value of this variable is set to 0, the shell checks for mail before displaying each prompt. MAILCHECKis usually set in your.profilefile. SHELL Specifies your default shell. This variable should be set and
exported by your.profilefile.
PS1 Specifies the default Bourne shell prompt, and its default value is$. PS1is usually set in your.profilefile. If PS1is not set, the shell uses the standard primary prompt string.
PS2 Specifies the secondary prompt string – the string that the shell displays when it requires more input after you enter a command line. The standard secondary prompt string is a> symbol followed by a space. PS2is usually set in your .profilefile. IfPS2is not set, the shell uses the standard secondary prompt string.
2222222222222222222222222222222222222222222222222222222222222222222
8.3.4
Built-In Commands
Table 8-11 describes selected Bourne shell commands that are of the most interest to general users. For a complete list of Bourne shell built-in commands, see thesh(1) reference page.
Table 8-11: Built-In Bourne Shell Commands
22222222222222222222222222222222222222222222222222222222222222222222 Command Description
22222222222222222222222222222222222222222222222222222222222222222222 cd Allows you to change directories. If no directory is specified, the
value of theHOMEshell variable is used. TheCDPATHshell variable defines the search path for this command.a
echo Writes arguments to the standard output.b
export Marks the specified variable for automatic export to the environments of subsequently executed commands. pwd Displays the current directory.c
set Assigns and displays variable values.d
times Displays the accumulated user and system times for processes run from the shell.
trap Runs a specified command when the shell receives a specified signal.d
umask Specifies the permissions to be subtracted for all new files created.e
unset Removes values that have been assigned to variables.d
22222222222222222222222222222222222222222222222222222222222222222222 Table notes:
a. For more information about thecdcommand, see Chapter 4, and the sh(1) reference page.
b. For more information about theechocommand, see Section 8.3.1 and thesh(1) reference page.
c. For more information about thepwdcommand, see Chapter 2.
d. For more information about theset, trap, andunsetcommands, see Chapter 7.
e. For more information about theumaskcommand, see Chapter 5 and Section 8.2.1.