Easily find issues by searching: #<Issue ID>
Example: #1832
Easily find members by searching in: <username>, <first name> and <last name>.
Example: Search smith, will return results smith and adamsmith
Advanced Bash-Scripting Guide: | ||
---|---|---|
Prev | Chapter 9. Another Look at Variables | Next |
Process ID of the current instance of Bash. This is not the same as the $$ variable, but it often gives the same result.
bash4$ echo $$ 11015 bash4$ echo $BASHPID 11015 bash4$ ps ax | grep bash4 11015 pts/2 R 0:00 bash4 |
#!/bin/bash4 echo "\$\$ outside of subshell = $$" # 9602 echo "\$BASH_SUBSHELL outside of subshell = $BASH_SUBSHELL" # 0 echo "\$BASHPID outside of subshell = $BASHPID" # 9602 echo ( echo "\$\$ inside of subshell = $$" # 9602 echo "\$BASH_SUBSHELL inside of subshell = $BASH_SUBSHELL" # 1 echo "\$BASHPID inside of subshell = $BASHPID" ) # 9603 # Note that $$ returns PID of parent process. |
An environmental variable pointing to a Bash startup file to be read when a script is invoked
A variable indicating the subshell level. This is a new addition to Bash, version 3.
See Example 21-1 for usage.
A 6-element array containing version information about the installed release of Bash. This is similar to $BASH_VERSION, below, but a bit more detailed.
# Bash version info: for n in 0 1 2 3 4 5 do echo "BASH_VERSINFO[$n] = ${BASH_VERSINFO[$n]}" done # BASH_VERSINFO[0] = 3 # Major version no. # BASH_VERSINFO[1] = 00 # Minor version no. # BASH_VERSINFO[2] = 14 # Patch level. # BASH_VERSINFO[3] = 1 # Build version. # BASH_VERSINFO[4] = release # Release status. # BASH_VERSINFO[5] = i386-redhat-linux-gnu # Architecture # (same as $MACHTYPE). |
$BASH_VERSION
The version of Bash installed on the system
bash$ echo $BASH_VERSION 3.2.25(1)-release |
tcsh% echo $BASH_VERSION BASH_VERSION: Undefined variable. |
Checking $BASH_VERSION is a good method of determining which shell is running. $SHELL does not necessarily give the correct answer.
A colon-separated list of search paths available to the cd command, similar in function to the $PATH variable for binaries. The $CDPATH variable may be set in the local ~/.bashrc file.
bash$ cd bash-doc bash: cd: bash-doc: No such file or directory bash$ CDPATH=/usr/share/doc bash$ cd bash-doc /usr/share/doc/bash-doc bash$ echo $PWD /usr/share/doc/bash-doc |
The top value in the directory stack [1] (affected by pushd and popd)
This builtin variable corresponds to the dirs command, however dirs shows the entire contents of the directory stack.
$EDITOR
The default editor invoked by a script, usually vi or emacs.
"effective" user ID number
Identification number of whatever identity the current user has assumed, perhaps by means of su.
The $EUID is not necessarily the same as the $UID. |
$FUNCNAME
Name of the current function
xyz23 () { echo "$FUNCNAME now executing." # xyz23 now executing. } xyz23 echo "FUNCNAME = $FUNCNAME" # FUNCNAME = # Null value outside a function. |
See also Example A-50.
$GLOBIGNORE
A list of filename patterns to be excluded from matching in globbing.
Groups current user belongs to
This is a listing (array) of the group id numbers for current user, as recorded in /etc/passwd and /etc/group.
root# echo $GROUPS 0 root# echo ${GROUPS[1]} 1 root# echo ${GROUPS[5]} 6 |
Home directory of the user, usually /home/username (see Example 10-7)
The hostname command assigns the system host name at bootup in an init script. However, the gethostname() function sets the Bash internal variable $HOSTNAME. See also Example 10-7.
$HOSTTYPE
host type
Like $MACHTYPE, identifies the system hardware.
bash$ echo $HOSTTYPE i686 |
internal field separator
This variable determines how Bash recognizes fields, or word boundaries, when it interprets character strings.
$IFS defaults to whitespace (space, tab, and newline), but may be changed, for example, to parse a comma-separated data file. Note that $* uses the first character held in $IFS. See Example 5-1.
bash$ echo "$IFS" (With $IFS set to default, a blank line displays.) bash$ echo "$IFS" | cat -vte ^I$ $ (Show whitespace: here a single space, ^I [horizontal tab], and newline, and display "$" at end-of-line.) bash$ bash -c 'set w x y z; IFS=":-;"; echo "$*"' w:x:y:z (Read commands from string and assign any arguments to pos params.) |
$IFS does not handle whitespace the same as it does other characters. |
Often set in the .bashrc or /etc/profile files, this variable controls collation order in filename expansion and pattern matching. If mishandled, LC_COLLATE can cause unexpected results in filename globbing.
As of version 2.05 of Bash, filename globbing no longer distinguishes between lowercase and uppercase letters in a character range between brackets. For example, ls [A-M]* would match both File1.txt and file1.txt. To revert to the customary behavior of bracket matching, set LC_COLLATE to C by an export LC_COLLATE=C in /etc/profile and/or ~/.bashrc. |
This internal variable controls character interpretation in globbing and pattern matching.
This variable is the line number of the shell script in which this variable appears. It has significance only within the script in which it appears, and is chiefly useful for debugging purposes.
# *** BEGIN DEBUG BLOCK *** last_cmd_arg=$_ # Save it. echo "At line number $LINENO, variable \"v1\" = $v1" echo "Last command argument processed = $last_cmd_arg" # *** END DEBUG BLOCK *** |
machine type
Identifies the system hardware.
Old working directory ("OLD-Print-Working-Directory", previous directory you were in).
$OSTYPE
operating system type
bash$ echo $OSTYPE linux |
Path to binaries, usually /usr/bin/, /usr/X11R6/bin/, /usr/local/bin, etc.
When given a command, the shell automatically does a hash table search on the directories listed in the path for the executable. The path is stored in the environmental variable, $PATH, a list of directories, separated by colons. Normally, the system stores the $PATH definition in /etc/profile and/or ~/.bashrc (see Appendix G).
bash$ echo $PATH /bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/sbin:/usr/sbin |
PATH=${PATH}:/opt/bin appends the /opt/bin directory to the current path. In a script, it may be expedient to temporarily add a directory to the path in this way. When the script exits, this restores the original $PATH (a child process, such as a script, may not change the environment of the parent process, the shell).
The current "working directory", ./, is usually omitted from the $PATH as a security measure. |
Array variable holding exit status(es) of last executed foreground pipe.
bash$ echo $PIPESTATUS 0 bash$ ls -al | bogus_command bash: bogus_command: command not found bash$ echo ${PIPESTATUS[1]} 127 bash$ ls -al | bogus_command bash: bogus_command: command not found bash$ echo $? 127 |
The members of the $PIPESTATUS array hold the exit status of each respective command executed in a pipe. $PIPESTATUS[0] holds the exit status of the first command in the pipe, $PIPESTATUS[1] the exit status of the second command, and so on.
About AquaClusters Privacy Policy Support Version - 19.0.2-4 AquaFold, Inc Copyright © 2007-2017