Shell Builtin variables (shell built-in variables)

Source: Internet
Author: User
Tags builtin

Shell Builtin variables (shell built-in variables) $ BASHThe path to the Bash binary itselfbash $ echo $ BASH/bin/bash $ BASH_ENVAn environmental variable pointing to a Bash startup file to be read when a script is invoked $ BASH_SUBSHELLA variable indicating the subshell level. this is a new addition to Bash, version 3.See Example 21-1 for usage. $ BASHPIDProcess ID of the current $ BASH_VERSINFO [n] A 6-element array contain Ing version information about the installed release of Bash. this is similarto $ BASH_VERSION, below, but a bit more detailed. for n in 0 1 2 3 4 5 doecho "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 s Tatus. # BASH_VERSINFO [5] = i386-redhat-linux-gnu # Architecture $ BASH_VERSIONThe version of Bash installed on the system $ CDPATHA colon-separated list of search paths available to the cd command, similar in function to the $ PATHvariable for binaries. the $ CDPATH variable may be set in the local ~ /. Bashrc file. $ DIRSTACKThe top value in the directory stack [41] (affected by pushd and popd) This builtin variable corresponds to the dirs command, however dirs shows the entire contents of thedirectory stack. $ EDITORThe default editor invoked by a script, usually vi or emacs. $ EUID "valid tive" user ID numberIdentification number of whatever identity the current user has assumed, perhaps by means Su. the $ EUID is not necessarily the same as the $ UID. $ FUNCNAMEName of the current functionxyz23 () {echo "$ FUNCNAME now executing. "# xyz23 now executing .} xyz23echo "FUNCNAME = $ FUNCNAME" # FUNCNAME = # Null value outside a function. $ GLOBIGNOREA list of filename patterns to be excluded from matching in globbing. $ GROUPSGroups current user belongs toThis is a listing (array) of the group id numbers f Or current user, as recorded in/etc/passwd and/etc/group. root # echo $ GROUPS0root # echo $ {GROUPS [1]} 1 root # echo $ {GROUPS [5]} 6 $ HOMEHome directory of the user, usually/home/username (see Example 10-7) $ HOSTNAMEThe hostname command assigns the system host name at bootup in an init script. however, thegethostname () function sets the Bash internal variable $ HOSTNAME. see also Example 10-7. $ HOSTTYPEhost TypeLike $ MACHTYPE, identifies the system hardware. $ IFSinternal field separatorThis variable determines how Bash recognizes fields, or word boundaries, when it interprets characterstrings. $ IFS defaults to whitespace (space, tab, and newline), but may be changed, for example, to parse acomma-separated data file. note that $ * uses the first character held in $ IFS. bash $ echo "$ IFS" (With $ IFS set 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 .) $ IGNOREEOFIgnore EOF: how many end-of-files (control-D) the shell will ignore before logging out. $ LC_COLLATE Often set in. bashrc or/etc/profile files, this variable controls collation order in filenameexpansion and pattern matching. if mishandled, LC_COLLATE can cause unexpected results infilename globbing. as of version 2.05 of Bash, filename globbing no longer distinguishes betweenlowercase and uppercase letters in a character range between brackets. for example, ls [A-M] * wocould match both File1.tx T and file1.txt. To revert to the customarybehavior of bracket matching, set LC_COLLATE to C by an export LC_COLLATE = C in/etc/profile and/or ~ /. Bashrc. $ LC_CTYPEThis internal variable controls character interpretation in globbing and pattern matching. $ LINENOThis variable is the line number of the shell script in which this variable appears. it has significanceonly 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_assist_arg "# *** end debug block *** $ MACHTYPEmachine typeIdentifies the system hardware. $ OLDPWDOld working directory ("OLD-Print-Working-Directory", previous directory you were in ). $ OSTYPEoperating system type $ PATHPath to binaries, usually/usr/bin/,/usr/X11R6/bin/,/usr/local/bin, etc. PATH =$ {PATH}:/opt/bin appends the/opt/bin directory The current path. in a script, itmay be used dient to temporarily add a directory to the path in this way. when the script exits, thisrestores the original $ PATH (a child process, such as a script, may not change the environment of theparent process, the shell ). $ PIPESTATUSArray variable holding exit status (es) of last executed foreground pipe. bash $ echo $ PIPESTATUS0bash $ ls-al | bogus_commandbash: B Ogus_command: command not foundbash $ echo $ {PIPESTATUS [1]} 127 bash $ ls-al | bogus_commandbash: bogus_command: command not foundbash $ echo $? Specify the members of the $ PIPESTATUS array hold the exit status of each respective command executedin 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 $ PPIDThe $ PPID of a process is the process ID (pid) of its parent process. [42] Compare this with the pidof command. $ PROMPT_COMMANDA variable holding a command Be executed just before the primary prompt, $ PS1 is to bedisplayed. $ PS1This is the main prompt, seen at the command-line. $ PS2The secondary prompt, seen when additional input is expected. it displays as "> ". $ PS3The tertiary prompt, displayed in a select loop (see Example 11-29 ). $ PS4The quartenary prompt, shown at the beginning of each line of output when invoking a script with the-x option. it dis Plays as "+ ". $ PWDWorking directory (directory you are in at the time) $ REPLYThe default value when a variable is not supplied to read. also applicable to select menus, but onlysupplies the item number of the variable chosen, not the value of the variable itself. $ SECONDSThe number of seconds the script has been running. $ SHELLOPTSThe list of enabled shell options, a readonly variable. $ SHLVLShell leve L, how deeply Bash is nested. [43] If, at the command-line, $ SHLVL is 1, then in a script itwill increment to 2. $ TMOUTIf the $ TMOUT environmental variable is set to a non-zero value time, then the shell prompt willtime out after $ time seconds. this will cause a logout. $ UIDUser ID numberCurrent user's user identification number, as recorded in/etc/passwdThis is the current user's real id, even if She has temporarily assumed another identity through su. $ UID is a readonly variable, not subject to change from the command line or within a script, and isthe counterpart to the id builtin. $0, $1, $2, etc. positional parameters, passed from command line to script, passed to a function, or set to a variable (see Example 4-5 and Example 15-16) $ # Number of command-line arguments [44] or positional param Eters (see Example 36-2) $ * All of the positional parameters, seen as a single word "$ *" must be quoted. $ @ Same as $ *, but each parameter is a quoted string, that is, the parameters are passed on intact, withoutinterpretation or expansion. this means, among other things, that each parameter in the argument listis seen as a separate word. the $ @ and $ * parameters differ only when between double quotes. #! /Bin/bash # If $ IFS set, but empty, # + then "$ *" and "$ @" do not echo positional params as expected. mecho () # Echo positional parameters. {echo "$1, $2, $3";} IFS = "" # Set, but empty. set a B c # Positional parameters. mecho "$ *" # abc, # ^ mecho $ * # a, B, cmecho $ @ # a, B, cmecho "$ @" # a, B, c $-Flags passed to script (using set ). $! PID (process ID) of last job run in background $ _ Special variable set to final argument of previous command executed $? Exit status of a command, function, or the script itself (see Example 24-7) $ Process ID (PID) of the script itself

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.