How and When to Use the Dot Command in Bash ?

First of, the dot command ( . ) is not to be confused with a dot file or a relative path notation. For example, the ~/.ssh folder is a hidden folder using the dot file notation, you will need to use ls -a to see that folder. And ./my-script.sh is a relative path to the script named “my-script.sh” in the current folder. Using the Dot command would be as such: . myscript.sh .

The dot command ( . ), aka full stop or period , is a command used to evaluate commands in the current execution context. In Bash, the source command is synonym to the dot command ( . ) and you can also pass parameters to the command, beware, this deviate from the POSIX specification.

👉 Unless you provide an exact path to the filename, Bash will use the $PATH entries to find the file to evaluate.

How to use the Dot Command in Bash?

When you run an executable script as ./my-script.sh , the commands are run in a new subshell, while when run as . my-script.sh the current shell context will be used. Generally, your current context is your terminal window. This mean that the dot command will apply changes to your current shell. Let’s look at the simple example below.

When run as an executable using ./my-script.sh , the A variable is not exported in your current shell and would just return an empty result.

When run the same script with the dot command using . my-script.sh , your current shell context will be changed.

When to use the Dot Command in Bash?

The most obvious use case for using the dot command is when you want to change your current context by setting new variables or changing some existing one. You may also have a script that expect to change your current directory by using cd . It may also be convenient when trying to run a script that doesn’t have the execute ( x ) permission.

Previous: Bourne Shell Variables , Up: Shell Variables   [ Contents ][ Index ]

5.2 Bash Variables

These variables are set or used by Bash, but other shells do not normally treat them specially.

A few variables used by Bash are described in different chapters: variables for controlling the job control facilities (see Job Control Variables ).

($_, an underscore.) At shell startup, set to the pathname used to invoke the shell or shell script being executed as passed in the environment or argument list. Subsequently, expands to the last argument to the previous simple command executed in the foreground, after expansion. Also set to the full pathname used to invoke each command executed and placed in the environment exported to that command. When checking mail, this parameter holds the name of the mail file.

The full pathname used to execute the current instance of Bash.

A colon-separated list of enabled shell options. Each word in the list is a valid argument for the -s option to the shopt builtin command (see The Shopt Builtin ). 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 readonly.

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. Assignments to BASHPID have no effect. If BASHPID is unset, it loses its special properties, even if it is subsequently reset.

An associative array variable whose members correspond to the internal list of aliases as maintained by the alias builtin. (see Bourne Shell Builtins ). Elements added to this array appear in the alias list; however, unsetting array elements currently does not cause aliases to be removed from the alias list. If BASH_ALIASES is unset, it loses its special properties, even if it is subsequently reset.

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 (see The Shopt Builtin for a description of the extdebug option to the shopt builtin). Setting extdebug after the shell has started to execute a script, or referencing this variable when extdebug is not set, may result in inconsistent values.

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 (see The Shopt Builtin for a description of the extdebug option to the shopt builtin). Setting extdebug after the shell has started to execute a script, or referencing this variable when extdebug is not set, may result in inconsistent values.

When referenced, this variable expands to the name of the shell or shell script (identical to $0 ; See Special Parameters , for the description of special parameter 0). Assignment to BASH_ARGV0 causes the value assigned to also be assigned to $0 . If BASH_ARGV0 is unset, it loses its special properties, even if it is subsequently reset.

An associative array variable whose members correspond to the internal hash table of commands as maintained by the hash builtin (see Bourne Shell Builtins ). Elements added to this array appear in the hash table; however, unsetting array elements currently does not cause command names to be removed from the hash table. If BASH_CMDS is unset, it loses its special properties, even if it is subsequently reset.

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. If BASH_COMMAND is unset, it loses its special properties, even if it is subsequently reset.

The value is used to set the shell’s compatibility level. See Shell Compatibility Mode , for a description of the various compatibility levels and their effects. The value may be a decimal number (e.g., 4.2) or an integer (e.g., 42) corresponding to the desired compatibility level. If BASH_COMPAT is unset or set to the empty string, the compatibility level is set to the default for the current version. If BASH_COMPAT is set to a value that is not one of the valid compatibility levels, the shell prints an error message and sets the compatibility level to the default for the current version. The valid values correspond to the compatibility levels described below (see Shell Compatibility Mode ). For example, 4.2 and 42 are valid values that correspond to the compat42 shopt option and set the compatibility level to 42. The current version is also a valid value.

If this variable is set when Bash is invoked to execute a shell script, its value is expanded and used as the name of a startup file to read before executing the script. See Bash Startup Files .

The command argument to the -c invocation option.

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.

A colon-separated list of directories in which the shell looks for dynamically loadable builtins specified by the enable command.

An array variable whose members are assigned by the ‘ =~ ’ binary operator to the [[ conditional command (see Conditional Constructs ). 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 n th parenthesized subexpression.

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]}

Incremented by one within each subshell or subshell environment when the shell begins executing in that environment. The initial value is 0. If BASH_SUBSHELL is unset, it loses its special properties, even if it is subsequently reset.

A readonly array variable (see Arrays ) whose members hold version information for this instance of Bash. The values assigned to the array members are as follows:

The major version number (the release ).

The minor version number (the version ).

The patch level.

The build version.

The release status (e.g., beta1 ).

The value of MACHTYPE .

The version number of the current instance of Bash.

If set to an integer corresponding to a valid file descriptor, Bash will write the trace output generated when ‘ set -x ’ is enabled to that file descriptor. This allows tracing output to be separated from diagnostic and error messages. The file descriptor is closed when BASH_XTRACEFD is unset or assigned a new value. Unsetting BASH_XTRACEFD or assigning it the empty string causes the trace output to be sent to the standard error. Note that setting BASH_XTRACEFD to 2 (the standard error file descriptor) and then unsetting it will result in the standard error being closed.

Set the number of exited child status values for the shell to remember. Bash will not allow this value to be decreased below a POSIX -mandated minimum, and there is a maximum value (currently 8192) that this may not exceed. The minimum value is system-dependent.

Used by the select command to determine the terminal width when printing selection lists. Automatically set if the checkwinsize option is enabled (see The Shopt Builtin ), or in an interactive shell upon receipt of a SIGWINCH .

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 (see Programmable Completion ).

The current command line. This variable is available only in shell functions and external commands invoked by the programmable completion facilities (see Programmable Completion ).

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 (see Programmable Completion ).

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 (see Programmable Completion ).

The key (or final key of a key sequence) used to invoke the current completion function.

The set of characters that the Readline library treats as word separators when performing word completion. If COMP_WORDBREAKS is unset, it loses its special properties, even if it is subsequently reset.

An array variable 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 (see Programmable Completion ).

An array variable from which Bash reads the possible completions generated by a shell function invoked by the programmable completion facility (see Programmable Completion ). Each array element contains one possible completion.

An array variable created to hold the file descriptors for output from and input to an unnamed coprocess (see Coprocesses ).

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 builtin. Assigning to members of this array variable may be used to modify directories already in the stack, but the pushd and popd builtins 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.

If Bash finds this variable in the environment when the shell starts with value ‘ t ’, it assumes that the shell is running in an Emacs shell buffer and disables line editing.

Expanded and executed similarly to BASH_ENV (see Bash Startup Files ) when an interactive shell is invoked in POSIX Mode (see Bash POSIX Mode ).

Each time this parameter is referenced, it expands to the number of seconds since the Unix Epoch as a floating point value with micro-second granularity (see the documentation for the C library function time for the definition of Epoch). Assignments to EPOCHREALTIME are ignored. If EPOCHREALTIME is unset, it loses its special properties, even if it is subsequently reset.

Each time this parameter is referenced, it expands to the number of seconds since the Unix Epoch (see the documentation for the C library function time for the definition of Epoch). Assignments to EPOCHSECONDS are ignored. If EPOCHSECONDS is unset, it loses its special properties, even if it is subsequently reset.

The numeric effective user id of the current user. This variable is readonly.

A colon-separated list of shell patterns (see Pattern Matching ) defining the list of filenames to be ignored by command search using PATH . Files whose full pathnames match one of these patterns are not considered executable files for the purposes of completion and command execution via PATH lookup. This does not affect the behavior of the [ , test , and [[ commands. Full pathnames in the command hash table are not subject to EXECIGNORE . Use this variable to ignore shared library files that have the executable bit set, but are not executable files. The pattern matching honors the setting of the extglob shell option.

The editor used as a default by the -e option to the fc builtin command.

A colon-separated list of suffixes to ignore when performing filename completion. A filename whose suffix matches one of the entries in FIGNORE is excluded from the list of matched filenames. A sample value is ‘ .o:~ ’

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. 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 builtin displays the current call stack using this information.

If set to a numeric value greater than 0, defines a maximum function nesting level. Function invocations that exceed this nesting level will cause the current command to abort.

A colon-separated list of patterns defining the set of file names to be ignored by filename expansion. If a file name matched by a filename expansion pattern also matches one of the patterns in GLOBIGNORE , it is removed from the list of matches. The pattern matching honors the setting of the extglob shell option.

An array variable containing the list of groups of which the current user is a member. Assignments to GROUPS have no effect. If GROUPS is unset, it loses its special properties, even if it is subsequently reset.

Up to three characters which control history expansion, quick substitution, and tokenization (see History Expansion ). The first character is the history expansion character, that is, the character which signifies the start of a history expansion, normally ‘ ! ’. The second character is the character which signifies ‘quick substitution’ when seen as the first character on a line, normally ‘ ^ ’. The optional third character is the character which indicates that the remainder of the line is a comment when found as the first character of a word, usually ‘ # ’. The history comment character causes history substitution to be skipped for the remaining words on the line. It does not necessarily cause the shell parser to treat the rest of the line as a comment.

The history number, or index in the history list, of the current command. Assignments to HISTCMD are ignored. If HISTCMD is unset, it loses its special properties, even if it is subsequently reset.

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 which match 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 .

The name of the file to which the command history is saved. The default value is ~/.bash_history .

The maximum number of lines contained in the history file. When this variable is assigned a value, the history file is truncated, if necessary, to contain no more than that number of lines by removing the oldest entries. The history file is also truncated to this size after writing it when a shell exits. If the value is 0, the history file is truncated to zero size. Non-numeric values and numeric values less than zero inhibit truncation. The shell sets the default value to the value of HISTSIZE after reading any startup files.

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 . The pattern matching honors the setting of the extglob shell option.

HISTIGNORE subsumes the function of HISTCONTROL . A pattern of ‘ & ’ is identical to ignoredups , and a pattern of ‘ [ ]* ’ is identical to ignorespace . Combining these two patterns, separating them with a colon, provides the functionality of ignoreboth .

The maximum number of commands to remember on the history list. If the value is 0, commands are not saved in the history list. Numeric values less than zero result in every command being saved on the history list (there is no limit). The shell sets the default value to 500 after reading any startup files.

If this variable is set and not null, its value is used as a format string for strftime to print the time stamp associated with each history entry displayed by the history builtin. 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.

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.

The name of the current host.

A string describing the machine Bash is running on.

Controls the action of the shell on receipt of an EOF character as the sole input. If set, the value denotes the number of consecutive EOF characters that can be read as the first character on an input line before the shell will exit. If the variable exists but does not have a numeric value, or has no value, then the default is 10. If the variable does not exist, then EOF signifies the end of input to the shell. This is only in effect for interactive shells.

The name of the Readline initialization file, overriding the default of ~/.inputrc .

If Bash finds this variable in the environment when the shell starts, it assumes that the shell is running in an Emacs shell buffer and may disable line editing depending on the value of TERM .

Used to determine the locale category for any category not specifically selected with a variable starting with LC_ .

This variable overrides the value of LANG and any other LC_ variable specifying a locale category.

This variable determines the collation order used when sorting the results of filename expansion, and determines the behavior of range expressions, equivalence classes, and collating sequences within filename expansion and pattern matching (see Filename Expansion ).

This variable determines the interpretation of characters and the behavior of character classes within filename expansion and pattern matching (see Filename Expansion ).

This variable determines the locale used to translate double-quoted strings preceded by a ‘ $ ’ (see Locale-Specific Translation ).

This variable determines the locale category used for number formatting.

This variable determines the locale category used for data and time formatting.

The line number in the script or shell function currently executing. If LINENO is unset, it loses its special properties, even if it is subsequently reset.

Used by the select command to determine the column length for printing selection lists. Automatically set if the checkwinsize option is enabled (see The Shopt Builtin ), or in an interactive shell upon receipt of a SIGWINCH .

A string that fully describes the system type on which Bash is executing, in the standard GNU cpu-company-system format.

How often (in seconds) that the shell should check for mail in the files specified in the MAILPATH or MAIL variables. 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.

An array variable created to hold the text read by the mapfile builtin when no variable name is supplied.

The previous working directory as set by the cd builtin.

If set to the value 1, Bash displays error messages generated by the getopts builtin command.

A string describing the operating system Bash is running on.

An array variable (see Arrays ) containing a list of exit status values from the processes in the most-recently-executed foreground pipeline (which may contain only a single command).

If this variable is in the environment when Bash starts, the shell enters POSIX mode (see Bash POSIX Mode ) before reading the startup 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

had been executed. When the shell enters POSIX mode, it sets this variable if it was not already set.

The process ID of the shell’s parent process. This variable is readonly.

If this variable is set, and is an array, the value of each set element is interpreted as a command to execute before printing the primary prompt ( $PS1 ). If this is set but not an array variable, its value is used as a command to execute instead.

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 Controlling the Prompt ). Characters removed are replaced with an ellipsis.

The value of this parameter is expanded like PS1 and displayed by interactive shells after reading a command and before the command is executed.

The value of this variable is used as the prompt for the select command. If this variable is not set, the select command prompts with ‘ #? ’

The value of this parameter is expanded like PS1 and the expanded value is the prompt printed before the command line is echoed when the -x option is set (see The Set Builtin ). The first character of the expanded value is replicated multiple times, as necessary, to indicate multiple levels of indirection. The default is ‘ + ’.

The current working directory as set by the cd builtin.

Each time this parameter is referenced, it expands to a random integer between 0 and 32767. Assigning a value to this variable seeds the random number generator. If RANDOM is unset, it loses its special properties, even if it is subsequently reset.

Any numeric argument given to a Readline command that was defined using ‘ bind -x ’ (see Bash Builtin Commands when it was invoked.

The contents of the Readline line buffer, for use with ‘ bind -x ’ (see Bash Builtin Commands ).

The position of the mark (saved insertion point) in the Readline line buffer, for use with ‘ bind -x ’ (see Bash Builtin Commands ). The characters between the insertion point and the mark are often called the region .

The position of the insertion point in the Readline line buffer, for use with ‘ bind -x ’ (see Bash Builtin Commands ).

The default variable for the read builtin.

This variable expands to the number of seconds since the shell was started. Assignment to this variable resets the count to the value assigned, and the expanded value becomes the value assigned plus the number of seconds since the assignment. The number of seconds at shell invocation and the current time are always determined by querying the system clock. If SECONDS is unset, it loses its special properties, even if it is subsequently reset.

This environment variable expands to the full pathname to the shell. If it is not set when the shell starts, Bash assigns to it the full pathname of the current user’s login shell.

A colon-separated list of enabled shell options. Each word in the list is a valid argument for the -o option to the set builtin command (see The Set Builtin ). 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 startup files. This variable is readonly.

Incremented by one each time a new instance of Bash is started. This is intended to be a count of how deeply your Bash shells are nested.

This variable expands to a 32-bit pseudo-random number each time it is referenced. The random number generator is not linear on systems that support /dev/urandom or arc4random , so each returned number has no relationship to the numbers preceding it. The random number generator cannot be seeded, so assignments to this variable have no effect. If SRANDOM is unset, it loses its special properties, even if it is subsequently reset.

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. The escape sequences and their meanings are as follows; the braces denote optional portions.

A literal ‘ % ’.

The elapsed time in seconds.

The number of CPU seconds spent in user mode.

The number of CPU seconds spent in system mode.

The CPU percentage, computed as (%U + %S) / %R.

The optional p is a digit specifying the precision, the number of fractional digits after a decimal point. A value of 0 causes no decimal point or fraction to be output. At most three places after the decimal point may be specified; values of p greater than 3 are changed to 3. If p is not specified, the value 3 is used.

The optional l specifies a longer format, including minutes, of the form MM m SS . FF s. The value of p determines whether or not the fraction is included.

If this variable is not set, Bash acts as if it had the value

If the value is null, no timing information is displayed. A trailing newline is added when the format string is displayed.

If set to a value greater than zero, TMOUT is treated as the default timeout for the read builtin (see Bash Builtin Commands ). The select command (see Conditional Constructs ) 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 a line of input after issuing the primary prompt. Bash terminates after waiting for that number of seconds if a complete line of input does not arrive.

If set, Bash uses its value as the name of a directory in which Bash creates temporary files for the shell’s use.

The numeric real user id of the current user. This variable is readonly.

How-To Geek

How to work with variables in bash.

Want to take your Linux command-line skills to the next level? Here's everything you need to know to start working with variables.

Hannah Stryker / How-To Geek

Quick Links

Variables 101, examples of bash variables, how to use bash variables in scripts, how to use command line parameters in scripts, working with special variables, environment variables, how to export variables, how to quote variables, echo is your friend, key takeaways.

  • Variables are named symbols representing strings or numeric values. They are treated as their value when used in commands and expressions.
  • Variable names should be descriptive and cannot start with a number or contain spaces. They can start with an underscore and can have alphanumeric characters.
  • Variables can be used to store and reference values. The value of a variable can be changed, and it can be referenced by using the dollar sign $ before the variable name.

Variables are vital if you want to write scripts and understand what that code you're about to cut and paste from the web will do to your Linux computer. We'll get you started!

Variables are named symbols that represent either a string or numeric value. When you use them in commands and expressions, they are treated as if you had typed the value they hold instead of the name of the variable.

To create a variable, you just provide a name and value for it. Your variable names should be descriptive and remind you of the value they hold. A variable name cannot start with a number, nor can it contain spaces. It can, however, start with an underscore. Apart from that, you can use any mix of upper- and lowercase alphanumeric characters.

Here, we'll create five variables. The format is to type the name, the equals sign = , and the value. Note there isn't a space before or after the equals sign. Giving a variable a value is often referred to as assigning a value to the variable.

We'll create four string variables and one numeric variable,

my_name=Dave

my_boost=Linux

his_boost=Spinach

this_year=2019

Defining variables in Linux.

To see the value held in a variable, use the echo command. You must precede the variable name with a dollar sign $ whenever you reference the value it contains, as shown below:

echo $my_name

echo $my_boost

echo $this_year

Using echo to display the values held in variables in a terminal window

Let's use all of our variables at once:

echo "$my_boost is to $me as $his_boost is to $him (c) $this_year"

echo

The values of the variables replace their names. You can also change the values of variables. To assign a new value to the variable, my_boost , you just repeat what you did when you assigned its first value, like so:

my_boost=Tequila

my_boost=Tequila in a terminal window

If you re-run the previous command, you now get a different result:

echo

So, you can use the same command that references the same variables and get different results if you change the values held in the variables.

We'll talk about quoting variables later. For now, here are some things to remember:

  • A variable in single quotes ' is treated as a literal string, and not as a variable.
  • Variables in quotation marks " are treated as variables.
  • To get the value held in a variable, you have to provide the dollar sign $ .
  • A variable without the dollar sign $ only provides the name of the variable.

Correct an incorrect examples of referencing variables in a terminal window

You can also create a variable that takes its value from an existing variable or number of variables. The following command defines a new variable called drink_of_the_Year, and assigns it the combined values of the my_boost and this_year variables:

drink_of-the_Year="$my_boost $this_year"

echo drink_of_the-Year

drink_of-the_Year=

Scripts would be completely hamstrung without variables. Variables provide the flexibility that makes a script a general, rather than a specific, solution. To illustrate the difference, here's a script that counts the files in the /dev directory.

Type this into a text file, and then save it as fcnt.sh (for "file count"):

#!/bin/bashfolder_to_count=/devfile_count=$(ls $folder_to_count | wc -l)echo $file_count files in $folder_to_count

Before you can run the script, you have to make it executable, as shown below:

chmod +x fcnt.sh

chmod +x fcnt.sh in a terminal window

Type the following to run the script:

./fcnt.sh in a terminal window

This prints the number of files in the /dev directory. Here's how it works:

  • A variable called folder_to_count is defined, and it's set to hold the string "/dev."
  • Another variable, called file_count , is defined. This variable takes its value from a command substitution. This is the command phrase between the parentheses $( ) . Note there's a dollar sign $ before the first parenthesis. This construct $( ) evaluates the commands within the parentheses, and then returns their final value. In this example, that value is assigned to the file_count variable. As far as the file_count variable is concerned, it's passed a value to hold; it isn't concerned with how the value was obtained.
  • The command evaluated in the command substitution performs an ls file listing on the directory in the folder_to_count variable, which has been set to "/dev." So, the script executes the command "ls /dev."
  • The output from this command is piped into the wc command. The -l (line count) option causes wc to count the number of lines in the output from the ls command. As each file is listed on a separate line, this is the count of files and subdirectories in the "/dev" directory. This value is assigned to the file_count variable.
  • The final line uses echo to output the result.

But this only works for the "/dev" directory. How can we make the script work with any directory? All it takes is one small change.

Many commands, such as ls and wc , take command line parameters. These provide information to the command, so it knows what you want it to do. If you want ls to work on your home directory and also to show hidden files , you can use the following command, where the tilde ~ and the -a (all) option are command line parameters:

Our scripts can accept command line parameters. They're referenced as $1 for the first parameter, $2 as the second, and so on, up to $9 for the ninth parameter. (Actually, there's a $0 , as well, but that's reserved to always hold the script.)

You can reference command line parameters in a script just as you would regular variables. Let's modify our script, as shown below, and save it with the new name fcnt2.sh :

#!/bin/bashfolder_to_count=$1file_count=$(ls $folder_to_count | wc -l)echo $file_count files in $folder_to_count

This time, the folder_to_count variable is assigned the value of the first command line parameter, $1 .

The rest of the script works exactly as it did before. Rather than a specific solution, your script is now a general one. You can use it on any directory because it's not hardcoded to work only with "/dev."

Here's how you make the script executable:

chmod +x fcnt2.sh

chmod +x fcnt2.sh in a terminal window

Now, try it with a few directories. You can do "/dev" first to make sure you get the same result as before. Type the following:

./fnct2.sh /dev

./fnct2.sh /etc

./fnct2.sh /bin

./fnct2.sh /dev in a terminal window

You get the same result (207 files) as before for the "/dev" directory. This is encouraging, and you get directory-specific results for each of the other command line parameters.

To shorten the script, you could dispense with the variable, folder_to_count , altogether, and just reference $1 throughout, as follows:

#!/bin/bash file_count=$(ls $1 wc -l) echo $file_count files in $1

We mentioned $0 , which is always set to the filename of the script. This allows you to use the script to do things like print its name out correctly, even if it's renamed. This is useful in logging situations, in which you want to know the name of the process that added an entry.

The following are the other special preset variables:

  • $# : How many command line parameters were passed to the script.
  • $@ : All the command line parameters passed to the script.
  • $? : The exit status of the last process to run.
  • $$ : The Process ID (PID) of the current script.
  • $USER : The username of the user executing the script.
  • $HOSTNAME : The hostname of the computer running the script.
  • $SECONDS : The number of seconds the script has been running for.
  • $RANDOM : Returns a random number.
  • $LINENO : Returns the current line number of the script.

You want to see all of them in one script, don't you? You can! Save the following as a text file called, special.sh :

#!/bin/bashecho "There were $# command line parameters"echo "They are: $@"echo "Parameter 1 is: $1"echo "The script is called: $0"# any old process so that we can report on the exit statuspwdecho "pwd returned $?"echo "This script has Process ID $$"echo "The script was started by $USER"echo "It is running on $HOSTNAME"sleep 3echo "It has been running for $SECONDS seconds"echo "Random number: $RANDOM"echo "This is line number $LINENO of the script"

Type the following to make it executable:

chmod +x special.sh

fig13 in a terminal window

Now, you can run it with a bunch of different command line parameters, as shown below.

./special.sh alpha bravo charlie 56 2048 Thursday in a terminal window

Bash uses environment variables to define and record the properties of the environment it creates when it launches. These hold information Bash can readily access, such as your username, locale, the number of commands your history file can hold, your default editor, and lots more.

To see the active environment variables in your Bash session, use this command:

env | less in a terminal window

If you scroll through the list, you might find some that would be useful to reference in your scripts.

List of environment variables in less in a terminal window

When a script runs, it's in its own process, and the variables it uses cannot be seen outside of that process. If you want to share a variable with another script that your script launches, you have to export that variable. We'll show you how to this with two scripts.

First, save the following with the filename script_one.sh :

#!/bin/bashfirst_var=alphasecond_var=bravo# check their valuesecho "$0: first_var=$first_var, second_var=$second_var"export first_varexport second_var./script_two.sh# check their values againecho "$0: first_var=$first_var, second_var=$second_var"

This creates two variables, first_var and second_var , and it assigns some values. It prints these to the terminal window, exports the variables, and calls script_two.sh . When script_two.sh terminates, and process flow returns to this script, it again prints the variables to the terminal window. Then, you can see if they changed.

The second script we'll use is script_two.sh . This is the script that script_one.sh calls. Type the following:

#!/bin/bash# check their valuesecho "$0: first_var=$first_var, second_var=$second_var"# set new valuesfirst_var=charliesecond_var=delta# check their values againecho "$0: first_var=$first_var, second_var=$second_var"

This second script prints the values of the two variables, assigns new values to them, and then prints them again.

To run these scripts, you have to type the following to make them executable:

chmod +x script_one.shchmod +x script_two.sh

chmod +x script_one.sh in a terminal window

And now, type the following to launch script_one.sh :

./script_one.sh

./script_one.sh in a terminal window

This is what the output tells us:

  • script_one.sh prints the values of the variables, which are alpha and bravo.
  • script_two.sh prints the values of the variables (alpha and bravo) as it received them.
  • script_two.sh changes them to charlie and delta.
  • script_one.sh prints the values of the variables, which are still alpha and bravo.

What happens in the second script, stays in the second script. It's like copies of the variables are sent to the second script, but they're discarded when that script exits. The original variables in the first script aren't altered by anything that happens to the copies of them in the second.

You might have noticed that when scripts reference variables, they're in quotation marks " . This allows variables to be referenced correctly, so their values are used when the line is executed in the script.

If the value you assign to a variable includes spaces, they must be in quotation marks when you assign them to the variable. This is because, by default, Bash uses a space as a delimiter.

Here's an example:

site_name=How-To Geek

site_name=How-To Geek in a terminal window

Bash sees the space before "Geek" as an indication that a new command is starting. It reports that there is no such command, and abandons the line. echo shows us that the site_name variable holds nothing — not even the "How-To" text.

Try that again with quotation marks around the value, as shown below:

site_name="How-To Geek"

site_name=

This time, it's recognized as a single value and assigned correctly to the site_name variable.

It can take some time to get used to command substitution, quoting variables, and remembering when to include the dollar sign.

Before you hit Enter and execute a line of Bash commands, try it with echo in front of it. This way, you can make sure what's going to happen is what you want. You can also catch any mistakes you might have made in the syntax.

LinuxSimply

Home > Bash Scripting Tutorial > Bash Scripting Basics > Executing Bash script > A Complete Overview of Bash “dot” Command [With 2 Examples]

A Complete Overview of Bash “dot” Command [With 2 Examples]

Monira Akter Munny

The dot command , also known as the ‘ source command ‘ , is an essential part of Bash that allows users to execute scripts within the current shell. In this writing, I will discuss when & how to use the command with practical examples.

Key Takeaways

  • Learning about the Bash dot command .
  • Learning how & when to use the dot command in Bash scripting.

Free Downloads

The “dot” command.

The dot command is a special shell built-in command denoted by a single dot (‘ . ’) that executes the content of a file and is passed as an argument in the current shell session. When you use this command to execute a script, it reads & executes commands from the specified script file as they were typed directly into the current shell session.

Command Syntax >

Here, the filename can be with the absolute or relative path location of the script file.

When to Use the “dot” Command in Bash?

In bash, use the “dot” command when you want to change your current context by setting new variables or changing some existing ones. Moreover, use the command,

  • To run a shell script that needs to be executed in the current shell context, for example, a script that uses the cd command to change the current directory, you can use the dot command in Bash.
  • To run a shell script that does not have execute permissions.
  • To source a configuration file, functions from another script or just to modify environment variables.

Difference Between “dot” Command & Other Uses of Dot Symbol

DO NOT confuse the dot command with the dot file or relative path notation. A dot file is a file whose name starts with a dot (.) , also known as a “hidden” file. And these hidden files or directories’ names starting with a dot are not shown in listings by default.

Another use of the dot symbol is in directory & file paths, a single dot (.) is used to represent the current directory , and a double dot (..) represents the parent directory .

2 Practical Examples of Bash “dot” Command

The dot command is basically a shorter approach for the source command . In other words, a symbol (.) that represents the source command. So, you also check ‘ What are the Usages of Bash Source ’ for learning basic concepts of bash sourcing. Anyway, here I will show two practical examples using the dot command.

Example 1: Loading Environment Variables Using Bash “dot” Command

Loading environment variables is particularly useful when you have multiple scripts that require the same set of variables. Instead of duplicating the variable definitions in each script, you can store them in a file & source that file using the dot command in each script. Go through the following steps to see the process:

Steps to Follow >

➊ At first, launch an Ubuntu Terminal.

➋ Now, write the following command to open a file in the nano text editor:

➌ Afterward, write the following script in the nano editor:

Script (env_var.sh) >

➍ Then, press CTRL+S to save the file & press CTRL+X to exit the nano editor.

➎ After that, write the following script file ( load_env_var ) in the same way as the previous script & save it.

Script (load_env_var.sh) >

➏ Then, use the following command to make the script executable:

  • chmod : Changes the permission of files and directories.
  • u+x: Argument with chmod command to add the executable permission for the user.
  • load_env_var: File which you want to make executable.

➐ Finally, write the following command to run the ‘load_env_var.sh’ script to check if the variables in the ‘env_var.sh’ script have been loaded successfully or not:

Load environment varinables using bash dot command

Example 2: Sourcing Configuration File Using Bash “dot” Command

In this example, I will show how you can source the configuration variables from ‘config.sh’ & use them in my main script named ‘run_config.sh’ using the dot command. This way you can easily include and use configuration settings from a separate file within your main script.

For that, let’s check out the contents of the two scripts:

Script (config.sh) >

Script (run_config.sh) >

Now, write the following command to run the ‘run_config.sh’ script to check if the variables in the ‘config.sh’ script have been loaded successfully or not:

Source configuration script file using bash dot command

In conclusion, the dot command is a powerful tool to run shell scripts from within the current shell. Moreover, it can also be used in a variety of situations due to its versatile usage areas. Hope this article helps you to understand the importance & usage of the command.

People Also Ask

Related Articles

  • How to make a File Executable in Bash [2 Methods]
  • What are the Usages of Bash Source [3 Practical Examples]
  • How to Run a Bash Script [2 Methods with Cases]
  • How to Run Bash Commands in Parallel [4 Ways with Examples]

<< Go Back to Executing Bash Script | Bash Scripting Basics | Bash Scripting Tutorial

Monira Akter Munny

Monira Akter Munny

Hello!! This is Monira Akter Munny. I'm a Linux content developer executive here, at SOFTEKO company. I have completed my B.Sc. in Engineering from Rajshahi University of Engineering & Technology in the Electrical & Electronics department. I'm more of an online gaming person who also loves to read blogs & write. As an open-minded person ready to learn & adapt to new territory, I'm always excited to explore the Linux world & share it with you! Read Full Bio

Leave a Comment Cancel reply

Save my name, email, and website in this browser for the next time I comment.

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

What is the 'dot space filename' command doing in bash?

When using bash shell, I sometimes keep environment variables in a text file which I copy/paste the content of, eg exports.txt:

Someone showed me instead of copy/paste, I could type in the terminal

which would have the same effect as copy/paste.

What is the mechanism by which this 'dot space filename' command works? It's hard to think of search terms for it.

I want to understand what is happening and the more general details of what this one-liner is doing.

iancoleman's user avatar

  • 24 Run help . This is so short the Stack Exchange engine thinks it's too short to be a comment. –  Wildcard Oct 19, 2016 at 3:13
  • 5 I wonder why all these questions occur also in this site. They have been answered many times in Stack Overflow , Ask Ubuntu and Unix & Linux . –  fedorqui Oct 19, 2016 at 12:33
  • To run dot-space, you'd need to type '. ' args , with single or double quotes. Otherwise the unquoted space is eaten up by bash when it parses the line into tokens (see "word splitting" in the bash manual). –  Peter Cordes Oct 19, 2016 at 19:58
  • 1 In bash, an alternate name for . is source , which literally means "source commands from this file," at least to me. –  jpaugh Oct 20, 2016 at 16:22
  • 1 An even more common question on Unix & Linux is unix.stackexchange.com/questions/58514 (and unix.stackexchange.com/questions/17815 and unix.stackexchange.com/questions/43882 and unix.stackexchange.com/questions/312573 and unix.stackexchange.com/questions/308109 and ...) –  JdeBP Oct 20, 2016 at 16:59

3 Answers 3

The . ("dot") command is a synonym/shortcut for the shell's built-in source command.

It causes the named shell script to be read in and executed within the current shell context (rather than a subshell). This allows the sourced script to modify the environment of the calling shell, such as setting variables and defining shell functions and aliases.

Spiff's user avatar

  • 51 Actually, source is a non-standard and non-portable synonym/shortcut for the POSIX-defined "dot" ( . ) command, not the other way around. –  terdon Oct 19, 2016 at 10:28
  • 9 bash provides a non-standard source and a non-standard . in non-POSIX mode, both of which search the current directory even if it isn't part of $PATH . In POSIX mode, it provides a standard . which doesn't search the current directory, and no source . In neither mode is source synonymous with POSIX's . command. –  hvd Oct 19, 2016 at 20:06

While the two existing answers are already excellent, I feel the example where the effect is the most "noticeable" so to say, is missing.

Say I have a file script.sh with the following contents:

If I would run this script normally ( sh script.sh ), I'd see this:

But if I where to source the script ( . script.sh ), I'd end up with this:

Notice how in the second case the working directory of our main shell has changed!

This is because (as pointed out in the other answers) the first example runs in its own subshell (the sh process we start with the sh -command, this could have been basically any shell, bash , dash , you name it), it changes directory there, does nothing and closes. While the second example runs in our main shell, and thus changes directory there!

Olle Kelderman's user avatar

Here is an example.

Script file: mytest.sh

if you try to print any of the above variables you will get nothing

but if you do

it will print 1

Just a visual answer of what Spiff wrote

raism's user avatar

  • So interpreting your example, using export is only if those variables are to be used in subshells. I could omit export in the file if the variables are only to be used in the current shell. Is that right? –  iancoleman Oct 19, 2016 at 2:36
  • 1 Quite right and I could say yes. However the use of the export command is more useful or more understandable if you think about the shell environment variables. For example $HOME or $DISPLAY. Yes you could use the export command to export a variable on your shell session or any subshells but it will gone as soon as you terminate that session. –  raism Oct 19, 2016 at 3:12

You must log in to answer this question.

Not the answer you're looking for browse other questions tagged bash export ..

  • The Overflow Blog
  • Exploring the inclusive tech revolution sponsored post
  • Would you trust an AI bot to find the fix for vulnerabilities in your code?
  • Featured on Meta
  • Site maintenance - Saturday, February 24th, 2024, 14:00 - 22:00 UTC (9 AM - 5...
  • Upcoming privacy updates: removal of the Activity data section and Google...

Hot Network Questions

  • On a tinted (reflective) window, why do I need to look from up close to see inside?
  • Movie about a team of people drilling to the center of the Earth to save humanity
  • Is there any satellite that uses LOX as oxidizer?
  • If the tidal bulge on the earth speeds the moon up, how does the moon move to a higher orbit?
  • Is the metric topology determined by its convergent sequences?
  • How to make a circle mesh with smooth coronas at different heights?
  • Impact of Ryan and Heninger's CRYPTO 2023 paper on post quantum cryptosystems
  • How much time do we need to decide if the replacement hydraulic fluid is inappropriate for our brake system or not?
  • How can Australia can be a member of the Antarctic Treaty while still making a territorial claim in the region?
  • tput does not try /dev/tty (?)
  • Ordering with repeats
  • Changing the highlighted row of tabularray in beamer
  • What is the word for the feeling when the piano key catches at the bottom of a press. The word for when the jack slips
  • If making your own microcontroller board, what types of pins may be used as GPIO pins?
  • Impedance matching and termination resistor
  • Why is everything based on likelihoods even though likelihoods are so small?
  • Get list of all expiring memberships, but excluding all those that have been "renewed" with another membership type
  • Hiding a star cluster
  • Spot The Difference
  • Why are my new switches operating in reverse?
  • What exactly is transmission time?
  • What's the word similar to jittery in spelling or pronunciation, but means some privately-run transportation by small vehicles?
  • Unable to understand what confidence interval means
  • What spares were taken on Apollo missions, and what was left behind? The question of gloves

bash variables with dots

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

How to set environment variables separated by dots

I have to set an environment variable separated by dot in my tomcat startup script. For example

I know shell doesn't accept dot separated variables. Is there a work around ?

I found somewhere that we can use env variable but that doesnt seem to work. I used

Can anyone help me please ?

  • command-line
  • environment-variables

muru's user avatar

2 Answers 2

Thanks a lot for your reply AB. However i found a much better solution. I simply added in the CATALINA_OPTS variable of tomcat in the file /usr/share/tomcat7/bin/setenv.sh :

This worked exactly as I wanted.

I do not understand why that is required for Tomcat. All configuratios are in eg: /etc/tomcat7/server.xml . I have worked for several years with Tomcat, but this kind of configuration I've never needed. Anyway here is your answer.

or with Java:

Create a runnable jar

and test with:

Community's user avatar

You must log in to answer this question.

Not the answer you're looking for browse other questions tagged command-line bash scripts environment-variables tomcat7 ..

  • The Overflow Blog
  • Exploring the inclusive tech revolution sponsored post
  • Would you trust an AI bot to find the fix for vulnerabilities in your code?
  • Featured on Meta
  • Site maintenance - Saturday, February 24th, 2024, 14:00 - 22:00 UTC (9 AM - 5...
  • Upcoming privacy updates: removal of the Activity data section and Google...

Hot Network Questions

  • Early computer art - reproducing Georg Nees "Schotter" and "K27"
  • Ingenuity extended static mission science possibilites
  • If the tidal bulge on the earth speeds the moon up, how does the moon move to a higher orbit?
  • Partial derivative of the Gibbs free energy with respect to temperature at constant enthalpy
  • Unable to understand what confidence interval means
  • Changing the highlighted row of tabularray in beamer
  • Why are my new switches operating in reverse?
  • If making your own microcontroller board, what types of pins may be used as GPIO pins?
  • If I don't log in the desktop environments, does the desktop enviroment still cost RAM?
  • White is missing
  • Were Mr. Darcy and Mr. Bennet formally equal in rank?
  • How might civilization develop if hunter-gatherers and/or early agrarian civilizations had access to highly advanced technology?
  • Why is everything based on likelihoods even though likelihoods are so small?
  • Enumerate the Phat-fingered-lights-out numbers
  • Does psychophysical harmony strongly point toward theism?
  • Advisor's Move to Another University: Should I Identify as a Visiting Student or Visiting Researcher?
  • The problem of philosophy?
  • Measuring a voltage signal ranging from -2 to 2 volts into a 16 bit ADC circuit
  • Markets in Germany with a large selection of seafood
  • How to make a circle mesh with smooth coronas at different heights?
  • What is the technical definition of "clone" that makes the K1810VM88 (К1810ВМ88) not a clone of the 8088?
  • Is this diesel gun concept feasible?
  • Was "coven" used as a term for a group of witches in 1608 or was another term in use?
  • Why is there a phasor in the transfer function of an ideal LPF?

bash variables with dots

IMAGES

  1. How to Use Variables in Bash Shell Scripts

    bash variables with dots

  2. How to use Variables in Bash Programming

    bash variables with dots

  3. Bash Script: define las variables Bash y sus tipos

    bash variables with dots

  4. How to use Variables in Bash

    bash variables with dots

  5. Variables in Bash/Shell Scripts and How To Use Them [Tutorial]

    bash variables with dots

  6. Bash Basics #2: Use Variables in Bash Scripts

    bash variables with dots

VIDEO

  1. BASH PROGRAMMING (SYNTAX,VARIABLES AND OPERATORS)

  2. 003-Bash: Variables, Conditions, Loops

  3. Geometry Bash 2 Trailer

  4. Section-5: Vidoe-10 : Command Line Arguments to provide inputs for Variables of Bash Shell Script

  5. Linux BASH: Create Local Env Variables #shorts

  6. Bash Course for Complete Beginners (sysadmin

COMMENTS

  1. Reference to a bash variable whose name contains dot

    Oct 22, 2014 at 11:40 i'm using a tool that run my bash and it has env variable with dotted name... - Farvardin Oct 22, 2014 at 11:42 2 Can you confirm you have that variable? It might be that your tool is not creating the variable you think it is. - AncientSwordRage Oct 22, 2014 at 11:45 3

  2. Exporting a variable with dot (.) in it

    How to export a variable which has dot in it. I get 'invalid variable name' when I tried : export my.home=/tmp/someDir -ksh: my.home=/tmp/someDir: invalid variable name Even escaping metacharacter dot (.) din't helped either $ export my\.home=/tmp/someDir export: my.home=/tmp/someDir: is not an identifier environment-variables ksh Share

  3. Can shell variable name include a hyphen or dash (-)?

    10 Answers Sorted by: 88 I've never met a Bourne-style shell that allowed - in a variable name. Only ASCII letters (of either case), _ and digits are supported, and the first character must not be a digit. If you have a program that requires an environment variable that doesn't match the shell restrictions, launch it with the env program.

  4. Passing a bash command-line argument containing a dot

    Solution: Read artifacts to be copied into an array from the command-line create dest path and source path strings by using the correct directory prefixes use a for loop to scp each artifact (having figured out the paths) Here's the simple script which is doing 1 (read artifacts into an array):

  5. How do I set an environmental variable with a dot?

    1 Answer. That is because a name with a dot—and you can believe your shell here—is not a valid identifier. From man bash: name A word consisting only of alphanumeric characters and underscores, and beginning with an alphabetic character or an underscore. Also referred to as an identifier. The dot is not an alphanumeric character and it's ...

  6. bash

    15 I tried doing that with export and set env, but it did not work. how to do it? for example ~/directory$ export a.home=1 bash: export: `a.home=1': not a valid identifier bash environment-variables console Share Improve this question Follow edited Oct 13, 2011 at 7:38 enzotib 93.3k 11 167 179 asked Oct 13, 2011 at 7:26 UAdapter 17.5k 38 80 102

  7. How and When to Use the Dot Command in Bash?

    The dot command (. ), aka full stop or period, is a command used to evaluate commands in the current execution context. In Bash, the source command is synonym to the dot command (.) and you can also pass parameters to the command, beware, this deviate from the POSIX specification.

  8. Bash Variables (Bash Reference Manual)

    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 .

  9. bash

    1 This would be much easier to answer if you could give us a minimal working example of the script that reproduces this error. - terdon ♦ Jun 24, 2014 at 17:21 @steeldriver It's valid ksh93 syntax (see glenn's answer), and this looks like a plausible use case for it. - Gilles 'SO- stop being evil'

  10. How to Use Variables in Bash Shell Scripts

    Using variables in bash shell scripts. In the last tutorial in this series, you learned to write a hello world program in bash. #! /bin/bash echo 'Hello, World!'. That was a simple Hello World script. Let's make it a better Hello World. Let's improve this script by using shell variables so that it greets users with their names.

  11. Defining a Bash Variable With or Without 'export'

    To handle this special case, bash provides the source command. The source command, or the dot (.) command, executes the bash script in the current shell context without creating a child shell. Therefore, we don't need the export command in the sourced script. The source command is useful to load variables and functions into the bash shell:

  12. How to Work with Variables in Bash

    Examples of Bash Variables How to Use Bash Variables in Scripts How to Use Command Line Parameters in Scripts Working with Special Variables Environment Variables How to Export Variables How to Quote Variables echo Is Your Friend Key Takeaways Variables are named symbols representing strings or numeric values.

  13. A Complete Overview of Bash "dot" Command [With 2 Examples]

    Learning about the Bash dot command. Learning how & when to use the dot command in Bash scripting. Free Downloads Download the Practice Files The "dot" Command The dot command is a special shell built-in command denoted by a single dot (' . ') that executes the content of a file and is passed as an argument in the current shell session.

  14. What is the 'dot space filename' command doing in bash?

    ("dot") command is a synonym/shortcut for the shell's built-in source command. It causes the named shell script to be read in and executed within the current shell context (rather than a subshell). This allows the sourced script to modify the environment of the calling shell, such as setting variables and defining shell functions and aliases.

  15. bash

    1 This isn't a job for the shell and printf. Use a proper text-processing tool (e.g. awk ). - don_crissti Jan 2, 2018 at 16:17 Add a comment 1 Answer Sorted by: 7 Add the line of dots to the string that goes to printf, and have printf cut it to length. In shell: $ for x in a bbb cccccc ; do printf '%.20s %s\n' "$x.................................."

  16. How to set environment variables separated by dots

    3 Thanks a lot for your reply AB. However i found a much better solution. I simply added in the CATALINA_OPTS variable of tomcat in the file /usr/share/tomcat7/bin/setenv.sh: export CATALINA_OPTS="-Dhost.name=localhost" This worked exactly as I wanted. Share

  17. What's the meaning of a dot before a command in shell?

    asked Feb 9, 2014 at 4:49 Jichao 1,967 2 13 8 Add a comment 6 Answers Sorted by: 166 A dot in that context means to "source" the contents of that file into the current shell. With source itself being a shell builtin command. And source and the dot operator being synonyms. Example Say I had the following contents in a sample.sh file.

  18. bash

    In Bash, there appear to be several variables which hold special, consistently-meaning values. For instance, ./myprogram &; echo $! will return the PID of the process which backgrounded myprogram. I know of others, such as $? which I think is the current TTY. Are there others? bash environment-variables dollar-sign Share Improve this question

  19. remove particular characters from a variable using bash

    I want to parse a variable (in my case it's development kit version) to make it dot(.) free. If version='2.3.3', desired output is 233. ... Using bash variable with escape character in awk to extract lines from file. 1. Best practice to read password, containing special characters like $!@`', into Bash script ...

  20. bash shell reworking variable replace dots by underscore

    bash shell reworking variable replace dots by underscore Ask Question Asked 4 years, 11 months ago Modified 1 year, 9 months ago Viewed 7k times 5 I can't see to get it working : echo $VERSIONNUMBER i get : v0.9.3-beta VERSIONNUMBERNAME=$ {VERSIONNUMBER:1} echo $VERSIONNUMBERNAME I get : 0.9.3-beta VERSION=$ {VERSIONNUMBERNAME/./_} echo $VERSION