Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the primitive types in bash scripting?

Tags:

types

bash

What are the primitive types in bash scripting?

I feel like this is a simple question, but it has been surprisingly hard to find the answer.

I know there are at least arrays because you can do commands such as

for file in *.less
  # code working with file

so that makes it appear like *.less is an array.

Also, there are string types, because if I have

a=y
b=z
c=$a+$b
echo $c
>> y+z

are there any other types besides this?


EDIT: After doing further research it also appears that there are associative arrays, which can be declared in the following manner

declare -A address

which I got from here. Are there any examples of other types?

like image 918
elju Avatar asked Aug 11 '26 06:08

elju


1 Answers

It's an interesting question, here's what I found:

bash supports several programming primitives shared by most programming languages. It can perform choices (if then else, case), it can loop (for,while, until) and it has functions (function). http://dasher.wustl.edu/chem478/software/unix-tools/bash.html

Bash variables are untyped.

Unlike many other programming languages, Bash does not segregate its variables by "type." 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. http://tldp.org/LDP/abs/html/untyped.html

Bash provides one-dimensional indexed and associative array variables. http://www.gnu.org/software/bash/manual/html_node/Arrays.html#Arrays

like image 129
Cole Pilegard Avatar answered Aug 13 '26 03:08

Cole Pilegard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!