Bash: Declaring Variables in Shell Scripting

Valic —  November 16, 2010 — Leave a comment

In Bash Shell Scripting the variables do not need to  be declared.

However, if the variable is not declared it will only produce an empty string.  When you declare variables you are telling the shell what value the variable contains.  In this example, the variable $var, note that it can be lower case, has a value of “time”.

Each time the variable is called it will have this value.  You can also declare variables with the declare command.



declare var=time

If you had a variable constructed without declaring the value it would look like this:


Or you may call a variable that has no value attached with something like this:

echo $VAR

If the VAR variable has not been declared you just get an empty string.


Posts Twitter Facebook

Editor in Chief at Debian-Tutorials, Linux enthusiast.

No Comments

Be the first to start the conversation.

Leave a Reply