Bash is an untyped language because it has only one type - character string, but here is mind twister which will make people doubt:
Essentially, Bash variables are character strings, but, depending on context, Bash permits arithmetic operations and comparisons on variables. The determining factor is whether the value of a variable contains only digits
People can think - "Huh it distinguishes digits, even so, they are passed around as numbers... so maybe it has types". Here is how to reason about this, take for example plus operation it takes 2 string value and returns a string
plus = (string, string) -> string
in case of two input strings contain only digits it will return another one with only digits in it (and maybe minus sign, or dot as fraction separator, but this doesn't matter for example). On the other side, a can construct function like this
as you can see it has same properties as plus (in case of two input strings contain only digits it will return another one with only digits in it), but it is not reasonable arithmetic operation. What matters from type system point of view is that it all variables are strings, even so, it seems that some strings have special properties (in given example they to represent numbers).
Does this explanation helps or more confuses? I'm trying to improve my skills on explaining things
Bash is an untyped language because it has only one type - character string, but here is mind twister which will make people doubt:
People can think - "Huh it distinguishes digits, even so, they are passed around as numbers... so maybe it has types". Here is how to reason about this, take for example
plus
operation it takes 2 string value and returns a stringin case of two input strings contain only digits it will return another one with only digits in it (and maybe minus sign, or dot as fraction separator, but this doesn't matter for example). On the other side, a can construct function like this
as you can see it has same properties as
plus
(in case of two input strings contain only digits it will return another one with only digits in it), but it is not reasonable arithmetic operation. What matters from type system point of view is that it all variables are strings, even so, it seems that some strings have special properties (in given example they to represent numbers).Does this explanation helps or more confuses? I'm trying to improve my skills on explaining things
Hehe, it's okay.