Why use typeset?

Hi,

All the scripts we have here use typeset instead of normal variables.
They don't have any parameters, they just get declared at the beginning of the scripts like this:

typeset var1 var2 var3

Could anyone tell me why this is done? I don't see the advantage in this over using normal variables.

It is probably a "best practices" convention in your shop. It may not be a best practice in reality.

In bash: typeset, when applied as in your example, prevents parameter substitution from being used on the variable. That is the only difference.

Using typeset -i (or other options) does have an effect on what the script can or cannot do with the variable.

1 Like