Shell Scripting – Shell Variables
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
In the last blog post, we have discussed user-defined global variables in the shell.
https://cloudaffaire.com/shell-scripting-environment-variables/
In this blog post, we will discuss shell variables that are defined by the shell itself. The shell variable is a special type of the variable used and set by the shell itself to store different shell configuration-related information. A shell variable can be global, user-specific, or session-specific. End users cannot define a new shell variable however they can set a pre-existing shell variable value if the variable is not read-only. Shell variables are mostly defined in uppercase letters as naming conventions.
Shell Scripting – Shell Variables
View all shell variables:
1 2 3 4 5 6 7 8 9 10 11 12 |
####################################### ## Shell Scripting | Shell Variables ## ####################################### ## Prerequisites: One Unix/Linux/POSIX-compliant operating system with bash shell ## -------------------- ## View shell variables ## -------------------- ## Get all shell variables available in your current session $ set -o posix; set ## will list all shell variables |
BASH: BASH returns the path to the bash binary itself. The default location is /bin/bash in most cases.
1 2 3 4 5 6 |
## ---- ## BASH ## ---- ## The path to the bash binary itself echo $BASH # returns /bin/bash in most cases |
BASHOPTS: A colon-separated list of enabled shell options. Each word in the list is a valid argument for the -s option to the shopt built in command. The options appearing in BASHOPTS are those reported as on by shopt. If this variable is in the environment when bash starts up, each shell option in the list will be enabled before reading any startup files. This variable is read-only.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
## -------- ## BASHOPTS ## -------- ## A colon-separated list of enabled shell options. echo $BASHOPTS ## returns checkwinsize:cmdhist:expand_aliases:extglob:extquote:force_fignore: ## histappend:interactive_comments:login_shell:progcomp:promptvars:sourcepath ## output may change depending upon shopt configuration ## Check shopt configuration shopt ## Set syslog_history shopt -s syslog_history echo $BASHOPTS ## returns checkwinsize:cmdhist:expand_aliases:extglob:extquote:force_fignore: ## histappend:interactive_comments:login_shell:progcomp:promptvars:sourcepath:syslog_history ## syslog_history appears in the output ## Unset syslog_history shopt -u syslog_history |
BASHPID: Expands to the process ID of the current bash process. This differs from $$ under certain circumstances, such as subshells that do not require bash to be re-initialized.
1 2 3 4 5 6 7 8 9 10 11 12 |
## ------- ## BASHPID ## ------- ## Process ID of the current instance of Bash. This is not the same as the $$ variable, but it often gives the same result. echo $BASHPID ## returns 14409 echo $$ ## returns 14409 bash ## forks a child process echo $BASHPID ## returns 14733 echo $$ ## returns 14733 exit ## exit the child process (echo $BASHPID; echo $$) ## returns 14868 and 14409 |
BASH_ALIASES: An associative array variable whose members correspond to the internal list of aliases as maintained by the alias built in. Elements added to this array appear in the alias list; unsetting array elements cause aliases to be removed from the alias list.
1 2 3 4 5 6 7 8 9 10 |
## ------------ ## BASH_ALIASES ## ------------ ## An associative array variable whose members correspond to the internal list of aliases as maintained by the alias built in. for k in "${BASH_ALIASES[@]}"; do printf '%s => %s\n' "$k" "${BASH_ALIASES[$k]}"; done ## returns all alias alias hello="pwd" ## set a new alias for k in "${BASH_ALIASES[@]}"; do printf '%s => %s\n' "$k" "${BASH_ALIASES[$k]}"; done ## returns all alias including hello ${BASH_ALIASES[hello]} ## returns your current working directory unalias hello ## remove the alias |
BASH_ARGC: An array variable whose values are the number of parameters in each frame of the current bash execution call stack. The number of parameters to the current subroutine (shell function or script executed with . or source) is at the top of the stack. When a subroutine is executed, the number of parameters passed is pushed onto BASH_ARGC. The shell sets BASH_ARGC only when in extended debugging mode.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
## --------- ## BASH_ARGC ## --------- ## An array variable whose values are the number of parameters in each frame of the current bash execution call stack. ## Set extdebug shopt -s extdebug ## Create a bash script vi myshscript.sh ------------------ #!/bin/bash echo $# ## returns 2 echo ${BASH_ARGC[0]} ## returns 2 ------------------ :wq ## Execute the script chmod +x myshscript.sh ./myshscript.sh hello world ## Unset extdebug shopt -u extdebug |
BASH_ARGV: An array variable containing all of the parameters in the current bash execution call stack. The final parameter of the last subroutine call is at the top of the stack; the first parameter of the initial call is at the bottom. When a subroutine is executed, the parameters supplied are pushed onto BASH_ARGV. The shell sets BASH_ARGV only when in extended debugging mode.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
## --------- ## BASH_ARGV ## --------- ## An array variable containing all of the parameters in the current bash execution call stack. ## Set extdebug shopt -s extdebug ## Create a bash script > myshscript.sh && vi myshscript.sh ------------------ #!/bin/bash echo $1 ## returns hello echo $2 ## returns world echo ${BASH_ARGV[0]} ## returns world echo ${BASH_ARGV[1]} ## returns hello ------------------ :wq ## Execute the script ./myshscript.sh hello world ## Unset extdebug shopt -u extdebug |
BASH_CMDS: An associative array variable whose members correspond to the internal hash table of commands as maintained by the hash built-in. Elements added to this array appear in the hash table; unsetting array elements cause commands to be removed from the hash table.
1 2 3 4 5 6 7 |
## --------- ## BASH_CMDS ## --------- ## An associative array variable whose members correspond to the internal hash table of commands as maintained by the hash built in. for k in "${BASH_CMDS[@]}"; do printf '%s => %s\n' "$k" "${BASH_CMDS[$k]}"; done ## returns all entry of hash table hash ## same output |
BASH_COMMAND: The command currently being executed or about to be executed, unless the shell is executing a command as the result of a trap, in which case it is the command executing at the time of the trap.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
## ------------ ## BASH_COMMAND ## ------------ ## BASH_COMMAND is the name of the currently executing command. echo $BASH_COMMAND ## returns echo $BASH_COMMAND ## Create a script > myshscript.sh && vi myshscript.sh ------------------ #!/bin/bash trap cleanup 1 2 3 15 cleanup() { echo "Command \"$BASH_COMMAND\" was executing when intruppted" exit 1 } while : do echo "hello" echo "world" done ------------------ :wq ## Execute the script ./myshscript.sh ## Press control + c to stop execution, returns hello or world |
BASH_ENV: If this parameter is set when bash is executing a shell script, its value is interpreted as a filename containing commands to initialize the shell, as in ~/.bashrc. The value of BASH_ENV is subjected to parameter expansion, command substitution, and arithmetic expansion before being interpreted as a file name. PATH is not used to search for the resultant file name.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
## -------- ## BASH_ENV ## -------- ## An environmental variable pointing to a Bash start up file to be read when a script is invoked. echo $BASH_ENV # in most cases BASH_ENV is not set ## Define your env configuration vi ~/myenv.sh ------------------- #!/bin/bash export myvar=cloudaffaire myfun () { echo "hello $@" } ------------------- :wq ## Create a script to call your custom env > myshscript.sh && vi myshscript.sh ------------------ #!/bin/bash myfun debjeet ## myfun definition is in ~/myenv.sh and passing debjeet parameter echo "welcome to $myvar" ## myvar is also defined in ~/myenv.sh ------------------ :wq ## Set BASH_ENV to your custom env file export BASH_ENV="~/myenv.sh" ## Execute the script ./myshscript.sh ## both myfun and myvar is availble to the script ## Unset BASH_ENV unset BASH_ENV ## Execute the script ./myshscript.sh ## error as your custom env is not available anymore |
BASH_EXECUTION_STRING: Returns the command argument to the bash -c invocation option.
1 2 3 4 5 6 |
## --------------------- ## BASH_EXECUTION_STRING ## --------------------- ## The command argument to the -c invocation option. bash -c 'echo $BASH_EXECUTION_STRING' ## BASH_EXECUTION_STRING returns the argument passed (echo $BASH_EXECUTION_STRING) |
BASH_LINENO: An array variable whose members are the line numbers in source files where each corresponding member of FUNCNAME was invoked. ${BASH_LINENO[$i]} is the line number in the source file (${BASH_SOURCE[$i+1]}) where ${FUNCNAME[$i]} was called (or ${BASH_LINENO[$i-1]} if referenced within another shell function). Use LINENO to obtain the current line number.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
## ----------- ## BASH_LINENO ## ----------- ## An array variable whose members are the line numbers in source files. ## Create a bash script > myshscript.sh && vi myshscript.sh ------------------ #!/bin/bash ## line 2 echo "hello world and i m in line no. $LINENO" ## line 3 ------------------ :wq ## Execute the script ./myshscript.sh ## returns hello world and i m in line no. 3 |
BASH_REMATCH: An array variable whose members are assigned by the =~ binary operator to the [[ conditional command. The element with index 0 is the portion of the string matching the entire regular expression. The element with index n is the portion of the string matching the nth parenthesized subexpression. This variable is read-only.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
## ------------ ## BASH_REMATCH ## ------------ ## An array variable whose members are assigned by the =~ binary operator to the [[ conditional command. ## Create a bash script > myshscript.sh && vi myshscript.sh ------------------ #!/bin/bash myvar='helloworld' if [[ $myvar =~ (hello)(.)(or)(ld) ]] then echo ${BASH_REMATCH[0]} ## returns helloworld echo ${BASH_REMATCH[1]} ## returns hello echo ${BASH_REMATCH[2]} ## returns w echo ${BASH_REMATCH[3]} ## returns or echo ${BASH_REMATCH[4]} ## returns ld fi ------------------ :wq ## Execute the script ./myshscript.sh |
BASH_SOURCE: An array variable whose members are the source filenames where the corresponding shell function names in the FUNCNAME array variable are defined. The shell function ${FUNCNAME[$i]} is defined in the file ${BASH_SOURCE[$i]} and called from ${BASH_SOURCE[$i+1]}.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
## ----------- ## BASH_SOURCE ## ----------- ## An array variable whose members are the source filenames where the corresponding shell function names in the FUNCNAME array ## variable are defined. ## Create three scripts vi main_script.sh ------------------- #!/bin/bash . script1.sh . script2.sh myfun1 ## call myfun1 in script1 wich in truns calls myfun2 in script2 ------------------- :wq vi script1.sh ------------------- #!/bin/bash myfun1() { echo "func1: FUNCNAME0 is ${FUNCNAME[0]}" echo "func1: BASH_SOURCE0 is ${BASH_SOURCE[0]}" echo "func1: FUNCNAME1 is ${FUNCNAME[1]}" echo "func1: BASH_SOURCE1 is ${BASH_SOURCE[1]}" myfun2 ## call myfun2 in script2 } ------------------- :wq vi script2.sh ------------------- #!/bin/bash myfun2() { echo "func2: FUNCNAME0 is ${FUNCNAME[0]}" echo "func2: BASH_SOURCE0 is ${BASH_SOURCE[0]}" echo "func2: FUNCNAME1 is ${FUNCNAME[1]}" echo "func2: BASH_SOURCE1 is ${BASH_SOURCE[1]}" echo "func2: FUNCNAME2 is ${FUNCNAME[2]}" echo "func2: BASH_SOURCE2 is ${BASH_SOURCE[2]}" } ------------------- :wq ## Chnage the execution mode and execute the main script chmod +x main_script.sh script1.sh script2.sh ./main_script.sh ## returns ## func1: FUNCNAME0 is myfun1 ## func1: BASH_SOURCE0 is script1.sh ## func1: FUNCNAME1 is main ## func1: BASH_SOURCE1 is ./main_script.sh ## func2: FUNCNAME0 is myfun2 ## func2: BASH_SOURCE0 is script2.sh ## func2: FUNCNAME1 is myfun1 ## func2: BASH_SOURCE1 is script1.sh ## func2: FUNCNAME2 is main ## func2: BASH_SOURCE2 is ./main_script.sh |
BASH_SUBSHELL: A variable indicating the subshell level. Incremented by one each time a subshell or subshell environment is spawned. The initial value is 0.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
## ------------- ## BASH_SUBSHELL ## ------------- ## A variable indicating the subshell level. ## Create a bash script > myshscript.sh && vi myshscript.sh ------------------ #!/bin/bash echo "in main shell = $BASH_SUBSHELL" # returns 0 ( echo "subshell one = $BASH_SUBSHELL" # returns 1 ( echo "subshell two= $BASH_SUBSHELL" # returns 2 ) ) echo "in main shell again = $BASH_SUBSHELL" # returns 0 ------------------ :wq ## Execute the script ./myshscript.sh |
BASH_VERSION: Expands to a string describing the version of this instance of bash. This is a read-only variable.
1 2 3 4 5 6 |
## ------------ ## BASH_VERSION ## ------------ ## The version of Bash installed on the system echo $BASH_VERSION ## returns your current bash version |
BASH_VERSINFO[n]: A read-only array variable whose members hold version information for this instance of bash. This is similar to BASH_VERSION but returns some extra information.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
## ---------------- ## BASH_VERSINFO[n] ## ---------------- ## 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. ## Create a bash script > myshscript.sh && vi myshscript.sh ------------------ #!/bin/bash for n in 0 1 2 3 4 5 do echo "BASH_VERSINFO[$n] = ${BASH_VERSINFO[$n]}" done ## returns ## BASH_VERSINFO[0] = 4 # Major version no. ## BASH_VERSINFO[1] = 2 # Minor version no. ## BASH_VERSINFO[2] = 46 # Patch level. ## BASH_VERSINFO[3] = 2 # Build version. ## BASH_VERSINFO[4] = release # Release status. ## BASH_VERSINFO[5] = x86_64-koji-linux-gnu # Architecture (same as $MACHTYPE). ------------------ :wq ## Execute the script ./myshscript.sh |
CDPATH: The search path for the cd command. This is a colon-separated list of directories in which the shell looks for destination directories specified by the cd command. A sample value is “.:~:/usr”
1 2 3 4 5 6 7 8 9 10 11 12 13 |
## ------ ## CDPATH ## ------ ## 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. mkdir -p dir1/dir2/dir3/dir4 echo $CDPATH # not set cd dir4 # No such file or directory CDPATH=dir1/dir2/dir3 cd dir4; pwd # returns /some/path/dir1/dir2/dir3/dir4 cd ../../../../ && rm -rf dir1 unset CDPATH |
COLUMNS: Used by the select compound command to determine the terminal width when printing selection lists. Automatically set upon receipt of a SIGWINCH.
1 2 3 4 5 6 7 8 9 |
## ------- ## COLUMNS ## ------- ## Used by the select compound command to determine the terminal width when printing selection lists. echo $COLUMNS ## returns 142 stty cols 132 ## set the new columns value to 132 echo $COLUMNS ## returns 132 stty cols 142 ## set back to value of 142 |
Autocompletion related variables:
COMPREPLY: An array variable from which bash reads the possible completions generated by a shell function invoked by the programmable completion facility.
COMP_CWORD: An index into ${COMP_WORDS} of the word containing the current cursor position. This variable is available only in shell functions invoked by the programmable completion facilities.
COMP_KEY: The key (or final key of a key sequence) used to invoke the current completion function.
COMP_LINE: The current command line. This variable is available only in shell functions and external commands invoked by the programmable completion facilities.
COMP_POINT: The index of the current cursor position relative to the beginning of the current command. If the current cursor position is at the end of the current command, the value of this variable is equal to ${#COMP_LINE}. This variable is available only in shell functions and external commands invoked by the programmable completion facilities.
COMP_TYPE: Set to an integer value corresponding to the type of completion attempted that caused a completion function to be called: TAB, for normal completion, ?, for listing completions after successive tabs, !, for listing alternatives on partial word completion, @, to list completions if the word is not unmodified, or %, for menu completion. This variable is available only in shell functions and external commands invoked by the programmable completion facilities.
COMP_WORDBREAKS: The set of characters that the readline library treats as word separators when performing word completion. If COMP_WORD‐BREAKS is unset, it loses its special properties, even if it is subsequently reset.
COMP_WORDS: An array variable (see Arrays below) consisting of the individual words in the current command line. The line is split into words as readline would split it, using COMP_WORDBREAKS as described above. This variable is available only in shell functions invoked by the programmable completion facilities.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
## -------------------------------- ## Autocompletion related variables ## -------------------------------- ## Create a autocomplition _myfun() { local cur COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} COMPREPLY=($( compgen -W '--help --verbose --version' -- $cur ) ) } complete -F _myfun myfun ## check myfun -- ## returns --help --verbose --version myfun --v ## returns --verbose --version |
DIRSTACK: An array variable containing the current contents of the directory stack. Directories appear in the stack in the order they are displayed by the dirs built in. Assigning to members of this array variable may be used to modify directories already in the stack, but the pushd and popd built ins must be used to add and remove directories. Assignment to this variable will not change the current directory. If DIRSTACK is unset, it loses its special properties, even if it is subsequently reset.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
## -------- ## DIRSTACK ## -------- ## The directory stack is a list of recently-visited directories. ## Create some directory mkdir -p main_dir/dir_1/dir_2/dir_3/dir_4 && cd main_dir ## Define variables dir1=dir_1/dir_2 dir2=dir_3/dir_4 echo "Now in directory `pwd`" ## returns /some/path/main_dir echo "DIRSTACK = $DIRSTACK" ## returns DIRSTACK = ~/some/path/main_dir pushd $dir1 echo "Now in directory `pwd`" ## returns /some/path/main_dir/dir_1/dir_2 echo "DIRSTACK = $DIRSTACK" ## returns DIRSTACK = ~/some/path/main_dir/dir_1/dir_2 pushd $dir2 echo "Now in directory `pwd`" ## returns /some/path/main_dir/dir_1/dir_2/dir_3/dir_4 echo "DIRSTACK = $DIRSTACK" ## returns DIRSTACK = ~/some/path/main_dir/dir_1/dir_2/dir_3/dir_4 popd echo "Now in directory `pwd`" ## returns /some/path/main_dir/dir_1/dir_2 echo "DIRSTACK = $DIRSTACK" ## returns DIRSTACK = ~/some/path/main_dir/dir_1/dir_2 popd echo "Now in directory `pwd`" ## returns /some/path/main_dir echo "DIRSTACK = $DIRSTACK" ## returns DIRSTACK = ~/some/path/main_dir cd .. rm -rf main_dir |
EUID: Expands to the effective user ID of the current user, initialized at shell startup. This variable is read-only. The $EUID is not necessarily the same as the $UID though most of the time they return the same value.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
## ---- ## EUID ## ---- ## EUID represents "effective" user ID number echo $EUID ## returns 1000 echo $UID ## returns 1000 ## One use of EUDI is to check if root ## Create a bash script > myshscript.sh && vi myshscript.sh ------------------ #!/bin/bash if [[ $EUID -eq 0 ]]; then echo "I am root" else echo "i am groot" fi ------------------ :wq ## Execute the script ./myshscript.sh ## returns i am groot ## Change to root and execute the script sudo -s ./myshscript.sh ## returns i am root exit |
FUNCNAME: An array variable containing the names of all shell functions currently in the execution call stack. The element with index 0 is the name of any currently-executing shell function. The bottom-most element (the one with the highest index) is “main”. This variable exists only when a shell function is executing. Assignments to FUNCNAME have no effect and return an error status. If FUNCNAME is unset, it loses its special properties, even if it is subsequently reset. This variable can be used with BASH_LINENO and BASH_SOURCE. Each element of FUNCNAME has corresponding elements in BASH_LINENO and BASH_SOURCE to describe the call stack. For instance, ${FUNCNAME[$i]} was called from the file ${BASH_SOURCE[$i+1]} at line number ${BASH_LINENO[$i]}. The caller built in displays the current call stack using this information.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
## -------- ## FUNCNAME ## -------- ## Name of the current function ## Create a function myfun () { echo "hello world from $FUNCNAME" } ## Call the function myfun ## returns hello world from myfun |
GLOBIGNORE: A colon-separated list of patterns defining the set of filenames to be ignored by pathname expansion. If a filename matched by a pathname expansion pattern also matches one of the patterns in GLOBIGNORE, it is removed from the list of matches.
1 2 3 4 5 6 7 8 9 10 11 |
## ---------- ## GLOBIGNORE ## ---------- ## A list of filename patterns to be excluded from matching in globbing. touch 1.zip 2.txt 3.iso 4.mp3 5.sql 6.py 7.json 8.yml 9.xml ## create some empty file GLOBIGNORE=*.zip:*.sh ## deifine the exclusion list for special charecter * rm -v * ## remove all files ls -l ## .zip and .sh files is not deleted unset GLOBIGNORE ## remove the variable rm 1.zip |
GROUPS: An array variable containing the list of groups of which the current user is a member. Assignments to GROUPS have no effect and return an error status. If GROUPS is unset, it loses its special properties, even if it is subsequently reset.
1 2 3 4 5 6 |
## ------ ## GROUPS ## ------ ## Groups current user belongs to. echo $GROUPS |
HISTCMD: The history number, or index in the history list, of the current command. If HISTCMD is unset, it loses its special properties, even if it is subsequently reset.
1 2 3 4 5 6 7 |
## ------- ## HISTCMD ## ------- ## The history number, or index in the history list, of the current command. echo $HISTCMD history | tail |
HISTCONTROL: A colon-separated list of values controlling how commands are saved on the history list. If the list of values includes ignorespace, lines which begin with a space character are not saved in the history list. A value of ignoredups causes lines matching the previous history entry to not be saved. A value of ignoreboth is shorthand for ignorespace and ignoredups. A value of erasedups causes all previous lines matching the current line to be removed from the history list before that line is saved. Any value not in the above list is ignored. If HISTCONTROL is unset, or does not include a valid value, all lines read by the shell parser are saved on the history list, subject to the value of HISTIGNORE. The second and subsequent lines of a multi-line compound command are not tested, and are added to the history regardless of the value of HISTCONTROL.
1 2 3 4 5 6 7 8 9 10 |
## ----------- ## HISTCONTROL ## ----------- ## A colon-separated list of values controlling how commands are saved on the history list. echo $HISTCONTROL ## returns ignoredups export HISTCONTROL=ignorespace:ignoredups ## set ignorespace along with ignoredups echo $HISTCONTROL ## returns ignorespace:ignoredups history ## returns history output export HISTCONTROL=ignoredups ## reset to previous config |
HISTFILE: The name of the file in which command history is saved. The default value is ~/.bash_history. If unset, the command history is not saved when an interactive shell exits.
1 2 3 4 5 6 7 |
## -------- ## HISTFILE ## -------- ## The name of the file in which command history is saved. echo $HISTFILE ## returns /home/user/.bash_history cat $HISTFILE ## view history file content |
HISTFILESIZE: The maximum number of lines contained in the history file. When this variable is assigned a value, the history file is truncated, if necessary, by removing the oldest entries, to contain no more than that number of lines. The default value is 500. The history file is also truncated to this size after writing it when an interactive shell exits.
1 2 3 4 5 6 |
## ------------ ## HISTFILESIZE ## ------------ ## The maximum number of lines contained in the history file. echo $HISTFILESIZE |
HISTIGNORE: A colon-separated list of patterns used to decide which command lines should be saved on the history list. Each pattern is anchored at the beginning of the line and must match the complete line (no implicit ‘*’ is appended). Each pattern is tested against the line after the checks specified by HISTCONTROL are applied. In addition to the normal shell pattern matching characters, ‘&’ matches the previous history line. ‘&’ may be escaped using a backslash; the backslash is removed before attempting a match. The second and subsequent lines of a multi-line compound command are not tested and are added to the history regardless of the value of HISTIGNORE.
1 2 3 4 5 6 7 8 9 10 |
## ---------- ## HISTIGNORE ## ---------- ## A colon-separated list of patterns used to decide which command lines should be saved on the history list. history | grep history ## returns all command having history in it export HISTIGNORE="history*" ## ignore any new command with history in it history | tail ## this will not be included as history history | tail ## confirms the same unset HISTIGNORE ## remove HISTIGNORE |
HISTSIZE: The number of commands to remember in the command history. The default value is 500.
1 2 3 4 5 6 |
## -------- ## HISTSIZE ## -------- ## The number of commands to remember in the command history. echo $HISTSIZE |
HISTTIMEFORMAT: If this variable is set and not null, its value is used as a format string for strftime(3) to print the time stamp associated with each history entry displayed by the history built in. If this variable is set, time stamps are written to the history file so they may be preserved across shell sessions. This uses the history comment character to distinguish timestamps from other history lines.
1 2 3 4 5 6 7 8 9 10 |
## -------------- ## HISTTIMEFORMAT ## -------------- ## If this variable is set and not null, its value is used as a format string for strftime(3) to print the time stamp associ‐ ## ated with each history entry displayed by the history built in history | tail export HISTTIMEFORMAT="%d/%m/%y %T " ## sets the timeformat history | tail ## time is also desplayed along with command unset HISTTIMEFORMAT |
HOME: The home directory of the current user; the default argument for the cd built in command. The value of this variable is also used when performing tilde expansion.
1 2 3 4 5 6 |
## ---- ## HOME ## ---- ## Home directory of the user, usually /home/username echo $HOME |
HOSTNAME: The hostname command assigns the system host name at bootup in an init script. However, the gethostname() function sets the Bash internal variable $HOSTNAME.
1 2 3 4 5 6 |
## -------- ## HOSTNAME ## -------- ## The hostname of the current system echo $HOSTNAME |
HOSTFILE: Contains the name of a file in the same format as /etc/hosts that should be read when the shell needs to complete a hostname. The list of possible hostname completions may be changed while the shell is running; the next time hostname completion is attempted after the value is changed, bash adds the contents of the new file to the existing list. If HOSTFILE is set, but has no value, or does not name a readable file, bash attempts to read /etc/hosts to obtain the list of possible hostname completions. When HOSTFILE is unset, the hostname list is cleared.
1 2 3 4 5 6 7 8 9 10 11 |
## -------- ## HOSTFILE ## -------- ## Contains the name of a file in the same format as /etc/hosts that should be read when the shell needs to complete a hostname. echo $HOSTFILE ## no alternet host file allocated echo "8.8.8.8 myhost" > ~/myhosts ## create your own host file export HOSTFILE=~/myhosts ## set HOSTFILE to your own host file ssh deb@ unset HOSTFILE ## unset HOSTFILE rm ~/myhosts |
HOSTTYPE: Automatically set to a string that uniquely describes the type of machine on which bash is executing. The default is system-dependent.
1 2 3 4 5 6 |
## -------- ## HOSTTYPE ## -------- ## Identifies the system hardware. echo $HOSTTYPE |
IFS: The Internal Field Separator that is used for word splitting after expansion and to split lines into words with the read built in command. The default value is <space><tab><newline>”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
## --- ## IFS ## --- ## IFS or internal field separator determines how Bash recognizes fields, or word boundaries, when it interprets character strings. ## Create a bash script > myshscript.sh && vi myshscript.sh ------------------ #!/bin/bash mystring="hello|world this|is debjeet|cloudaffaire" for word in $mystring; do echo "Word: $word" done ## returns ## Word: hello|world ## Word: this|is ## Word: debjeet|cloudaffaire IFS='|' for word in $mystring; do echo "Word: $word" done ## returns ## Word: hello ## Word: world this ## Word: is debjeet ## Word: cloudaffaire ------------------ :wq ## Execute the script ./myshscript.sh |
IGNOREEOF: Controls the action of an interactive shell on receipt of an EOF character as the sole input. If set, the value is the number of consecutive EOF characters that must be typed as the first characters on an input line before bash exits. If the variable exists but does not have a numeric value, or has no value, the default value is 10. If it does not exist, EOF signifies the end of input to the shell.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
## --------- ## IGNOREEOF ## --------- ## Controls the action of an interactive shell on receipt of an EOF character as the sole input. echo $IGNOREEOF ## currently not set set -o | grep ignoreeof ## confirms the same bash ## forks a new bash process ## press control + D ## exit immideatly as IGNOREEOF is not set export IGNOREEOF=3 ## set IGNOREEOF to 3 (3 times control + D needs to be pressed) bash ## forks another new bash process ## press control + D ## not exist in 1st go, need 3 times control + D unset IGNOREEOF |
locale related variables:
A locale is a set of language and cultural rules. These cover aspects such as language for messages, different character sets, lexicographic conventions, and so on. A program needs to be able to determine its locale and act accordingly to be portable to different cultures.
LANG: Used to determine the locale category for any category not specifically selected with a variable starting with LC_.
LC_ALL: This variable overrides the value of LANG and any other LC_ variable specifying a locale category.
LC_COLLATE: This variable determines the collation order used when sorting the results of pathname expansion, and determines the behavior of range expressions, equivalence classes, and collating sequences within pathname expansion and pattern matching.
LC_CTYPE: This variable determines the interpretation of characters and the behavior of character classes within pathname expansion and pattern matching.
LC_MESSAGES: This variable determines the locale used to translate double-quoted strings preceded by a $.
LC_NUMERIC: This variable determines the locale category used for number formatting.
LC_TIME: This variable determines the locale category used for time and date formatting.
LC_MONETARY: This variable determines the locale category used for monetary formatting.
LC_PAPER: This variable determines the locale category used for paper size.
LC_NAME: This variable determines the locale category used for name formatting.
LC_ADDRESS: This variable determines the locale category used for address formatting.
LC_TELEPHONE: This variable determines the locale category used for phone number formatting.
LC_MEASUREMENT: This variable determines the locale category used for the measurement unit.
LC_IDENTIFICATION: Metadata about the locale information
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
## ------------------------ ## locale related variables ## ------------------------ ## view current config locale ## returns ## LANG=en_US.UTF-8 ## LC_CTYPE="en_US.UTF-8" ## LC_NUMERIC="en_US.UTF-8" ## LC_TIME="en_US.UTF-8" ## LC_COLLATE="en_US.UTF-8" ## LC_MONETARY="en_US.UTF-8" ## LC_MESSAGES="en_US.UTF-8" ## LC_PAPER="en_US.UTF-8" ## LC_NAME="en_US.UTF-8" ## LC_ADDRESS="en_US.UTF-8" ## LC_TELEPHONE="en_US.UTF-8" ## LC_MEASUREMENT="en_US.UTF-8" ## LC_IDENTIFICATION="en_US.UTF-8" ## LC_ALL= ## View more details on a specifc variable locale -k LC_NUMERIC |
LINES: Used by the select compound command to determine the column length for printing selection lists. Automatically set upon receipt of a SIGWINCH.
1 2 3 4 5 6 7 8 9 |
## ----- ## LINES ## ----- ## Used by the select compound command to determine the column length for printing selection lists. echo $LINES ## returns 37 stty rows 47 ## set the new columns value to 47 echo $LINES ## returns 47 stty rows 37 ## set back to value of 37 |
LINENO: Each time this parameter is referenced, the shell substitutes a decimal number representing the current sequential line number (starting with 1) within a script or function. When not in a script or function, the value substituted is not guaranteed to be meaningful. If LINENO is unset, it loses its special properties, even if it is subsequently reset.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
## ------ ## LINENO ## ------ ## Each time this parameter is referenced, the shell substitutes a decimal number representing the current sequential line number ## Craete a script > myshscript.sh && vi myshscript.sh ------------------ #!/bin/bash # this is line 3 echo "hello world" # this is line 4 echo $LINENO # returns 5 ------------------ :wq ## Execute the script ./myshscript.sh |
MACHTYP: Automatically set to a string that fully describes the system type on which bash is executing, in the standard GNU cpu-company-system format. The default is system-dependent.
1 2 3 4 5 6 7 |
## -------- ## MACHTYPE ## -------- ## Automatically set to a string that fully describes the system type on which bash is executing, in the standard GNU cpu-com‐ ## pany-system format. The default is system-dependent. echo $MACHTYPE |
MAIL: If this parameter is set to a file or directory name and the MAILPATH variable is not set, bash informs the user of the arrival of mail in the specified file or Maildir-format directory.
1 2 3 4 5 6 7 |
## ---- ## MAIL ## ---- ## If this parameter is set to a file or directory name and the MAILPATH variable is not set, bash informs the user of the ## arrival of mail in the specified file or Maildir-format directory. echo $MAIL |
MAILCHECK: Specifies how often (in seconds) bash checks for mail. The default is 60 seconds. When it is time to check for mail, the shell does so before displaying the primary prompt. If this variable is unset, or set to a value that is not a number greater than or equal to zero, the shell disables mail checking.
1 2 3 4 5 6 |
## --------- ## MAILCHECK ## --------- ## Specifies how often (in seconds) bash checks for mail. echo $MAILCHECK |
MAILPATH: A colon-separated list of file names to be checked for mail. The message to be printed when mail arrives in a particular file may be specified by separating the file name from the message with a ‘?’. When used in the text of the message, $_ expands to the name of the current mailfile. Example: MAILPATH=’/var/mail/bfox?”You have mail”:~/shell-mail?”$_ has mail!”‘ Bash supplies a default value for this variable, but the location of the user mail files that it uses is system dependent (e.g., /var/mail/$USER).
1 2 3 4 5 6 |
## -------- ## MAILPATH ## -------- ## A colon-separated list of file names to be checked for mail. echo $MAILPATH |
MAPFILE: An array variable created to hold the text read by the mapfile builtin when no variable name is supplied.
1 2 3 4 5 6 7 8 9 10 11 |
## ------- ## MAPFILE ## ------- ## An array variable created to hold the text read by the mapfile built in when no variable name is supplied. mapfile -t < <(sudo ls /) ## create a mapfile without variable, output will be stored in MAPFILE for k in "${MAPFILE[@]}"; do printf '%s ' "$k"; done ## returns output of ls / unset MAPFILE mapfile -t mymap < <(sudo ls /) ## create a mapfile with variable, output will not be stored in MAPFILE for k in "${MAPFILE[@]}"; do printf '%s ' "$k"; done ## returns nothing as variable mymap was supplied unset MAPFILE |
OLDPWD: The previous working directory as set by the cd command.
1 2 3 4 5 6 |
## ------ ## OLDPWD ## ------ ## The previous working directory as set by the cd command. echo $OLDPWD |
Options related variables:
OPTARG: The value of the last option argument processed by the getopts built in command.
OPTIND: The index of the next argument to be processed by the getopts built in command.
OPTERR: If set to the value 1, bash displays error messages generated by the getopts built in command. OPTERR is initialized to 1 each time the shell is invoked or a shell script is executed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
## ------------------------- ## Options related variables ## ------------------------- ## Create a bash script > myshscript.sh && vi myshscript.sh ------------------ #!/bin/bash usage() { echo "Usage: $0 [-s <1|2>] [-p while getopts ":s:p:" o; do case "${o}" in s) s=${OPTARG} ((s == 1 || s == 2)) || usage ;; p) p=${OPTARG} ;; *) usage ;; esac done shift $((OPTIND-1)) if [ -z "${s}" ] || [ -z "${p}" ]; then usage fi echo "s = ${s}" echo "p = ${p}" echo "OPTERR = ${OPTERR}" ------------------ :wq ## Execute the script ./myshscript.sh ## returns Usage: $0 [-s <1|2>] [-p ./myshscript.sh -s 1 ## returns Usage: $0 [-s <1|2>] [-p ./myshscript.sh -s 10 -p ten ## returns Usage: $0 [-s <1|2>] [-p ./myshscript.sh -s 1 -p one ## returns s = 1 and p = one and OPTERR = 1 |
OSTYPE: Automatically set to a string that describes the operating system on which bash is executing. The default is system-dependent.
1 2 3 4 5 6 |
## ------ ## OSTYPE ## ------ ## Automatically set to a string that describes the operating system on which bash is executing. The default is system-depen‐dent. echo $OSTYPE |
PATH: The search path for commands. It is a colon-separated list of directories in which the shell looks for commands. A zero-length (null) directory name in the value of PATH indicates the current directory. A null directory name may appear as two adjacent colons, or as an initial or trailing colon. The default path is system-dependent, and is set by the administrator who installs bash. A common value is /usr/gnu/bin:/usr/local/bin:/usr/ucb:/bin:/usr/bin”.
1 2 3 4 5 6 |
## ---- ## PATH ## ---- ## The search path for commands. It is a colon-separated list of directories in which the shell looks for commands echo $PATH ## export PATH=$PATH:/place/with/the/file |
PIPESTATUS: An array variable containing a list of exit status values from the processes in the most-recently-executed foreground pipeline (which may contain only a single command).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
## ---------- ## PIPESTATUS ## ---------- ## An array variable containing a list of exit status values from the processes in the most-recently-exe‐ ## cuted foreground pipeline (which may contain only a single command). ## Create a bash script > myshscript.sh && vi myshscript.sh ------------------ #!/bin/bash true | false | true | false RC=( "${PIPESTATUS[@]}" ) echo "RC[0] = ${RC[0]}" # true = 0 echo "RC[1] = ${RC[1]}" # false = 1 echo "RC[2] = ${RC[2]}" # true = 0 echo "RC[3] = ${RC[3]}" # false = 1 ------------------ :wq ## Execute the script ./myshscript.sh |
PPID: The process ID of the shell’s parent. This variable is read-only.
1 2 3 4 5 6 |
## ---- ## PPID ## ---- ## The process ID of the shell's parent. This variable is read only. echo $PPID |
PWD: The current working directory as set by the cd command.
1 2 3 4 5 6 |
## --- ## PWD ## --- ## The current working directory as set by the cd command. echo $PWD |
POSIXLY_CORRECT: If this variable is in the environment when bash starts, the shell enters posix mode before reading the start up files, as if the –posix invocation option had been supplied. If it is set while the shell is running, bash enables posix mode, as if the command set -o posix had been executed.
1 2 3 4 5 6 7 8 9 10 |
## --------------- ## POSIXLY_CORRECT ## --------------- ## If this variable is in the environment when bash starts, the shell enters posix mode before reading the start up files, as if ## the --posix invocation option had been supplied. set -o | grep posix ## returns posix off export POSIXLY_CORRECT=1 ## sets POSIXLY_CORRECT set -o | grep posix ## returns posix on unset POSIXLY_CORRECT ## unset the variable |
PS1: The value of this parameter is expanded and used as the primary prompt string. The default value is \s-\v\$ ”.
1 2 3 4 5 6 7 8 9 |
## --- ## PS1 ## --- ## The value of this parameter is expanded (see PROMPTING below) and used as the primary prompt string. The default value is ``\s-\v\$ ''. ## Current primary prompt [user@host dir]$ export PS1="[\u@\h \W]\$ " echo $PS1 ## returns [\u@\h \W]\$ export PS1="cloudaffaire >" ## observe that the prompt changes to cloudaffaire > export PS1="[\u@\h \W]\$ " ## restore previous prompt |
PS2: The value of this parameter is expanded as with PS1 and used as the secondary prompt string. The default is > ”.
1 2 3 4 5 6 7 8 9 10 11 |
## --- ## PS2 ## --- ## The value of this parameter is expanded as with PS1 and used as the secondary prompt string. The default is ``> ''. ## Current secondary prompt > export PS2=">" echo $PS2 ## returns > export PS2=">>>>" echo "hello \ world" ## observe that the prompt changes to >>>> export PS2=">" ## restore previous prompt |
PS3: The value of this parameter is used as the prompt for the select command.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
## --- ## PS3 ## --- ## The value of this parameter is used as the prompt for the select command. ## Current select prompt echo $PS3 ## not set ## Create a bash script > myshscript.sh && vi myshscript.sh ------------------ #!/bin/bash PS3="Select a game (1-4): " ## sets PS3 select i in cricket football basketball exit do case $i in cricket) echo "You have selected Cricket";; football) echo "You have selected Football";; basketball) echo "You have selected Basketball";; exit) break;; esac done ------------------- :wq ## Execute the script ./myshscript.sh ## Returns ## 1) cricket ## 2) football ## 3) basketball ## 4) exit ## Select a game (1-4): 1 ## You have selected Cricket ## Select a game (1-4): 4 unset PS3 |
PS4: The value of this parameter is expanded as with PS1 and the value is printed before each command bash displays during an execution trace. The first character of PS4 is replicated multiple times, as necessary, to indicate multiple levels of indirection. The default is “+ ”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
## --- ## PS4 ## --- ## The value of this parameter is expanded as with PS1 and the value is printed before each command bash displays during an ## execution trace. The first character of PS4 is replicated multiple times, as necessary, to indicate multiple levels of ## indirection. The default is ``+ ''. ## Current PS4 value echo $PS4 ## returns + ## Create a bash script > myshscript.sh && vi myshscript.sh ------------------ #!/bin/bash export PS4='Line executing $LINENO+ and Command executing ' set -x echo "hello world" ls | wc -l du -sh ------------------ :wq ## Execute the script ./myshscript.sh export PS4="+" ## restore to previous value |
PROMPT_COMMAND: If set, the value is executed as a command prior to issuing each primary prompt.
1 2 3 4 5 6 7 8 |
## -------------- ## PROMPT_COMMAND ## -------------- ## If set, the value is executed as a command prior to issuing each primary prompt. echo $PROMPT_COMMAND ## not set export PROMPT_COMMAND="date" ## returns current date everytime you hit enter unset PROMPT_COMMAND ## remove PROMPT_COMMAND |
PROMPT_DIRTRIM: If set to a number greater than zero, the value is used as the number of trailing directory components to retain when expanding the \w and \W prompt string escapes. Characters removed are replaced with an ellipsis.
1 2 3 4 5 6 7 8 9 10 11 |
## -------------- ## PROMPT_DIRTRIM ## -------------- ## If set to a number greater than zero, the value is used as the number of trailing directory components to retain when ## expanding the \w and \W prompt string escapes (see PROMPTING below). Characters removed are replaced with an ellipsis. export PS1="[\u@\h \w]$ " ## was set to "[\u@\h \W]$ " mkdir -p dir1/dir2/dir3/dir4 && cd dir1/dir2/dir3/dir4 ## returns ~/some/path/dir1/dir2/dir3/dir4 export PROMPT_DIRTRIM=2 ## changes the prompt to ~/.../dir3/dir4 unset PROMPT_DIRTRIM ## remove PROMPT_DIRTRIM export PS1="[\u@\h \W]$ " ## restore previous value |
RANDOM: Each time this parameter is referenced, a random integer between 0 and 32767 is generated. The sequence of random numbers may be initialized by assigning a value to RANDOM. If RANDOM is unset, it loses its special properties, even if it is subsequently reset.
1 2 3 4 5 6 7 8 9 10 |
## ------ ## RANDOM ## ------ ## Each time this parameter is referenced, a random integer between 0 and 32767 is generated by default. echo $RANDOM ## returns a random integer between 0 and 32767 echo $RANDOM ## returns a random integer between 0 and 32767 echo $RANDOM ## returns a random integer between 0 and 32767 echo $((RANDOM%100+1)) ## returns a random integer between 1 and 100 echo $((RANDOM%= 1000)) ## returns a random integer less than 1000 |
REPLY: Set to the line of input read by the read built-in command when no arguments are supplied.
1 2 3 4 5 6 7 |
## ----- ## REPLY ## ----- ## Set to the line of input read by the read built in command when no arguments are supplied. read -p "Enter your name: " echo "hello $REPLY" |
SECONDS: Each time this parameter is referenced, the number of seconds since shell invocation is returned. If a value is assigned to SECONDS, the value returned upon subsequent references is the number of seconds since the assignment plus the value assigned. If SECONDS is unset, it loses its special properties, even if it is subsequently reset.
1 2 3 4 5 6 7 8 9 |
## ------- ## SECONDS ## ------- ## Each time this parameter is referenced, the number of seconds since shell invocation is returned. echo $SECONDS bash ## forks a new bash process echo $SECONDS exit ## return to previous process |
SHELL: The full pathname to the shell is kept in this environment variable. If it is not set when the shell starts, bash assigns to it the full pathname of the current user’s login shell.
1 2 3 4 5 6 |
## ----- ## SHELL ## ----- ## The full pathname to the shell is kept in this environment variable. echo $SHELL |
SHELLOPTS: A colon-separated list of enabled shell options. Each word in the list is a valid argument for the -o option to the set built in command. The options appearing in SHELLOPTS are those reported as on by set -o. If this variable is in the environment when bash starts up, each shell option in the list will be enabled before reading any start up files. This variable is read-only.
1 2 3 4 5 6 7 |
## --------- ## SHELLOPTS ## --------- ## A colon-separated list of enabled shell options. set -o | grep on echo $SHELLOPTS |
SHLVL: Returns the number of bash instance running. Incremented by one each time an instance of bash is started.
1 2 3 4 5 6 7 8 9 |
## ----- ## SHLVL ## ----- ## Incremented by one each time an instance of bash is started. echo $SHLVL bash echo $SHLVL exit |
TIMEFORMAT: The value of this parameter is used as a format string specifying how the timing information for pipelines prefixed with the time reserved word should be displayed. The % character introduces an escape sequence that is expanded to a time value or other information.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
## ---------- ## TIMEFORMAT ## ---------- ## The value of this parameter is used as a format string specifying how the timing information for pipelines prefixed with the ## time reserved word should be displayed. echo $TIMEFORMAT ## not set hence bash uses ;\nreal\t%3lR\nuser\t%3lU\nsys%3lS' format to display time output time cat myshscript.sh > /dev/null ## TIMEFORMAT can be used to display CPU utilization in a more in a more natural way than the standard time output TIMEFORMAT="%2lU user + %2lS system / %2lR elapsed = %P%% CPU Utilisation" time cat myshscript.sh > /dev/null ## returns 0m0.00s user + 0m0.00s system / 0m0.00s elapsed = 99.30% CPU Utilisation ## TIMEFORMAT can be used to display elapsed time in a more natural way than the standard time output TIMEFORMAT="%U user + %S system = %lR total elapsed time" time cat myshscript.sh > /dev/null ## returns 0.001 user + 0.000 system = 0m0.001s total elapsed time unset TIMEFORMAT |
TMOUT: If set to a value greater than zero, TMOUT is treated as the default timeout for the read built in. The select command terminates if input does not arrive after TMOUT seconds when input is coming from a terminal. In an interactive shell, the value is interpreted as the number of seconds to wait for input after issuing the primary prompt. Bash terminates after waiting for that number of seconds if input does not arrive.
1 2 3 4 5 6 7 8 9 10 |
## ----- ## TMOUT ## ----- ## If set to a value greater than zero, TMOUT is treated as the default timeout for the read built in. bash ## forks a new bash process echo $TMOUT export TMOUT=10 ## do nothing for 10 seconds, timed out waiting for input: auto-logout unset TMOUT ## unset the TMOUT |
TMPDIR: If set, bash uses its value as the name of a directory in which bash creates temporary files for the shell’s use.
1 2 3 4 5 6 |
## ------ ## TMPDIR ## ------ ## If set, bash uses its value as the name of a directory in which bash creates temporary files for the shell's use. echo $TMPDIR |
UID: Expands to the user ID of the current user, initialized at shell startup. This variable is read-only.
1 2 3 4 5 6 |
## --- ## UID ## --- ## Expands to the user ID of the current user, initialized at shell start up. This variable is read only. echo $UID |
Hope you have enjoyed this article. In the next blog post, we will discuss operators.