bash how to set variable


A variable is a temporary place to store information.

There is 2 kind of variables: local and global. Global variables are available in all bash instances. You can you command env or printenv to show global variables. Local variables are only available in the current bash instance.

Syntax of creating and setting variable is:


It is required no space before and after =. If you need to set two and more words to the variable use double quotes:

variable="one two three four"

To get value from a variable use the symbol "$". Example of setting to the variable "dir" path to the actual working directory:


Was this information helpful to you? You have the power to keep it alive.
Each donated € will be spent on running and expanding this page about UNIX Shell.