Example 1.
Adding to the console works well
pic@pic:~/Desktop$ a="$(date +%s)"
pic@pic:~/Desktop$ b="$(date +%s)"
pic@pic:~/Desktop$ echo $[a+b]
2844184057
pic@pic:~/Desktop$
Example 2.
It's the same, but the script
pic@pic:~/Desktop$ cat a.sh
#!bin/bash
a="$(date +%s)"
b="$(date +%s)"
echo $[a+b]pic@pic:~/Desktop$ sh a.sh
$[a+b]
pic@pic:~/Desktop$
Why do I get a different result? How to get the same result?
EDIT:
pic@pic:~/Desktop$ ls -l $(command -v sh)
lrwxrwxrwx 1 root root 4 sty 10 2014 /bin/sh -> dash
pic@pic:~/Desktop$ ./a.sh
bash: ./a.sh: Brak dostępu
pic@pic:~/Desktop$
EDIT -1 :
It works like a run so
pic@pic:~/Desktop$ . ./a.sh
2844188704
pic@pic:~/Desktop$
EDIT -2 :
Does not work
pic@pic:~/Desktop$ chmod +x a.sh
pic@pic:~/Desktop$ ./a.sh
bash: ./a.sh: bin/bash: zły interpreter: Nie ma takiego pliku ani katalogu
pic@pic:~/Desktop$
EDIT -3 :
Corrected
pic@pic:~/Desktop$ cat a.sh
#!/bin/bash
a="$(date +%s)"
b="$(date +%s)"
echo $[a+b]pic@pic:~/Desktop$ ./a.sh
2844189920
pic@pic:~/Desktop$
./a.shnot withsh a.sh.shis (or at least could be) a different shell thanbashand in your case apparently does not understand$[a+b]syntax. Check which shellshis linked to withls -l $(command -v sh).a.shis executable (x inls -l) do./a.shif not do. ./a.sh$((expression))The old format$[expression]is deprecated and will be removed in upcoming versions of bash."#!bin/bashthat should be#!/bin/bash. It is unlikely that you have bash in the subdirectorybinof the current directory. And because of that you are usingsh(dash?) on your system in the script$((expression))vs$[expression].