User Tools

Site Tools


Variables and Constants

In Bash, unless otherwise specified with the declare command, all the values are strings.

Note that no spaces are allowed before and after = and neither inside val: use %%“” to declare a string with spaces.

x=5  # it's a string
b="is a string with spaces"
y=$((5 + $x))  # assign the result of the math calc
echo $y  # print the val
c="$a $b"  # concatenate
echo $c
d=$(date '+%A %d  %B, %H:%M')  # assign the result of a command
echo $d

This is the output:

y = 10
c: this is a string with spaces
Thursday 26  March, 09:06
programming-languages/bash/var-const.txt · Last modified: 2020/04/03 09:36 (external edit)