# parameter and variable in programming languages

From Bash Reference Manual, a parameter:

A parameter is an entity that stores values.

It can be a name, a number, or one of the special characters listed below.

A variable:

A variable is a parameter denoted by a name.

1. Is a variable is a parameter A, denoted by a parameter B which is also a name? How do you understand the concept of a variable?

2. since a parameter stores values, does that mean a parameter is a block in memory?

3. I never heard of the concept of "parameter" in other languages such as C, C++, Python. Do the distinct concepts of parameter and of variable exist in programming languages besides bash? What are their definitions in programming languages?

Thanks.

• I suppose you shoud read a book on theory of programming languages to better learn the basic concepts and terminologies employed in that field. A function defined in a C code to compute a power of a number could have a head like "power(x,n)" where x and n are termed "formal parameters". When that function is applied, one may see something like "power(2,i)" where the variable i has been previously assigned a value e.g. 6 in order to compute the value 2**6. In that expression "power(2,i)" 2 and i are termed "actual parameters". – Mok-Kong Shen Oct 11 '14 at 17:24
• @Mok-KongShen: But here a parameter in bash is defined without the context of a function. – Tim Oct 11 '14 at 17:28
• You should learn a programming language. Programming has one thing in common with Tango and Polka. You do not learn them by reading books. Practice does help. – babou Oct 11 '14 at 20:49

## 1 Answer

Bash is a shell language for interacting with the computer on the command lines. These languages often have weird features dictated by expediency, sometimes disputable. I used the multics language long ago, and it was incredibly weird to program with. I actually do not know whether there has been serious scientific study of what would constitute a proper shell language.

In the case of bash, you can write shell scripts that you store in files, and can then call from the command line. When you call them, you can pass arguments to them, and the values thus passed are stored in order in the variables \$1 \$2 ... and can thus be accessed from wthin the script.

So \$1, \$2, etc. are just variable that you can use as you see fit. But they may also be used as standard locations to store the results of some standard commands, and they are location where the arguments passed to scripts are stored. hence the name parameter.

But ... What's in a name?

Regarding your other questions, you should find some answers in wikipedia, or learn some.programming language. They all have a variety of mechanisms to pass information to sub-program (whatever that may be). Hence it is not possible to answer simply your questions. There are parameters and variables, but they may come in different flavors, that depend on languages. Read a bit, before asking.

• Thanks. The manual was written in a way that a parameter is defined without the context of a function or a script. – Tim Oct 11 '14 at 22:19