The difference between parameter and variable in bash

Transfered from Linux Config Disqus comments:

Question:
Hi, in bash context what is the difference between parameter and variable?

Answer:

In a bash context a parameter is an entity that stores values. Furthermore, a parameter can be a name ( variable ), number ( positional parameter ) or special character ( special parameter ). Therefore, a variable is a parameter denoted by a name. ( see: man bash ). Let’s have a closer look on all three bash parameters:
Variable

Variable has a value assigned to it. It also can have 0 or more attributes. A value may be assigned to a variable by a following statement:


name=[value]

Example:

#!/bin/bash

myname="Gnu Bash"
printf "%s
" "$myname"

Positional parameter

Positional parameter is denoted by one or digits. It is assigned by one or more arguments supplied to a script upon the script execution.
Example:

 #!/bin/bash

printf "%s
" "My name is $1 $2"

Special Parameters

Special parameters are denoted by a one or more special characters from a following list: *, @, #, ?, -, $, !, 0 and _ . For example * expands to positional parameters. In other words it prints all arguments supplied on the command line upon the script execution:

 #!/bin/bash
echo $*

OUTPUT:

./special GNU Bash parameter vs variable
GNU Bash parameter vs variable

Linux questions and answers

In a bash context, a parameter is an entity that stores values. Parameter is a technical term which has only recently found its way into general use, unfortunately, without keeping its correct meaning. It uses special variables of bash. A variable is a parameter denoted by a name. Variable has a value assigned to it. It also can have 0 or more attributes.

Bash uses a tool called positional parameters to provide a means of entering data into a Bash program when it is invoked from the command line. Two special variables contain all of the positional parameters (except positional parameter 0): * and @.

Further reading: